github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/tests/operation_put_certificate_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/ravendb/ravendb-go-client/serverwide/certificates"
     6  	"github.com/stretchr/testify/assert"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  func putCertificateTest(t *testing.T, driver *RavenTestDriver) {
    12  	var err error
    13  
    14  	store := driver.getSecuredDocumentStoreMust(t)
    15  	assert.NotNil(t, store)
    16  	defer store.Close()
    17  
    18  	path := os.Getenv("RAVENDB_TEST_CA_PATH")
    19  	if !fileExists(path) {
    20  		fmt.Printf("Didn't find cert.crt file at '%s'. Set RAVENDB_TEST_CA_PATH env variable\n", path)
    21  		os.Exit(1)
    22  	}
    23  
    24  	certificate := loadTestCaCertificate(path)
    25  	assert.NotNil(t, certificate)
    26  	fmt.Printf("Loaded client certificate from '%s'\n", path)
    27  
    28  	certName := "Admin Certificate"
    29  	operation := certificates.OperationPutCertificate{
    30  		CertName:          certName,
    31  		CertBytes:         certificate.Raw,
    32  		SecurityClearance: certificates.ClusterAdmin.String(),
    33  		Permissions:       nil,
    34  	}
    35  
    36  	err = store.Maintenance().Server().Send(&operation)
    37  	assert.NoError(t, err)
    38  
    39  }
    40  
    41  func TestPutCertificateTest(t *testing.T) {
    42  	driver := createTestDriver(t)
    43  	destroy := func() {
    44  		destroyDriver(t, driver)
    45  	}
    46  
    47  	defer recoverTest(t, destroy)
    48  
    49  	putCertificateTest(t, driver)
    50  }