storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/event/target/nats_tls_test.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package target
    18  
    19  import (
    20  	"path"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	natsserver "github.com/nats-io/nats-server/v2/test"
    25  
    26  	xnet "storj.io/minio/pkg/net"
    27  )
    28  
    29  func TestNatsConnTLSCustomCA(t *testing.T) {
    30  	s, opts := natsserver.RunServerWithConfig(filepath.Join("testdata", "nats_tls.conf"))
    31  	defer s.Shutdown()
    32  
    33  	clientConfig := &NATSArgs{
    34  		Enable: true,
    35  		Address: xnet.Host{Name: "localhost",
    36  			Port:      (xnet.Port(opts.Port)),
    37  			IsPortSet: true},
    38  		Subject:       "test",
    39  		Secure:        true,
    40  		CertAuthority: path.Join("testdata", "certs", "root_ca_cert.pem"),
    41  	}
    42  
    43  	con, err := clientConfig.connectNats()
    44  	if err != nil {
    45  		t.Errorf("Could not connect to nats: %v", err)
    46  	}
    47  	defer con.Close()
    48  }
    49  
    50  func TestNatsConnTLSClientAuthorization(t *testing.T) {
    51  	s, opts := natsserver.RunServerWithConfig(filepath.Join("testdata", "nats_tls_client_cert.conf"))
    52  	defer s.Shutdown()
    53  
    54  	clientConfig := &NATSArgs{
    55  		Enable: true,
    56  		Address: xnet.Host{Name: "localhost",
    57  			Port:      (xnet.Port(opts.Port)),
    58  			IsPortSet: true},
    59  		Subject:       "test",
    60  		Secure:        true,
    61  		CertAuthority: path.Join("testdata", "certs", "root_ca_cert.pem"),
    62  		ClientCert:    path.Join("testdata", "certs", "nats_client_cert.pem"),
    63  		ClientKey:     path.Join("testdata", "certs", "nats_client_key.pem"),
    64  	}
    65  
    66  	con, err := clientConfig.connectNats()
    67  	if err != nil {
    68  		t.Errorf("Could not connect to nats: %v", err)
    69  	}
    70  	defer con.Close()
    71  }