...

Source file src/go.mongodb.org/mongo-driver/mongo/integration/client_side_encryption_spec_test.go

Documentation: go.mongodb.org/mongo-driver/mongo/integration

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  //go:build cse
     8  // +build cse
     9  
    10  package integration
    11  
    12  import (
    13  	"os"
    14  	"path"
    15  	"regexp"
    16  	"testing"
    17  )
    18  
    19  const (
    20  	encryptionSpecName = "client-side-encryption/legacy"
    21  )
    22  
    23  func verifyClientSideEncryptionVarsSet(t *testing.T) {
    24  	t.Helper()
    25  
    26  	// Existence of temporary AWS credentials (awsTempAccessKeyID, awsTempSessionToken and
    27  	// awsTempSessionToken) is verified when the variables are used in json_helpers_test
    28  	// because temporary AWS credentials are not always set.
    29  
    30  	if awsAccessKeyID == "" {
    31  		t.Fatal("AWS access key ID not set")
    32  	}
    33  	if awsSecretAccessKey == "" {
    34  		t.Fatal("AWS secret access key not set")
    35  	}
    36  	if azureTenantID == "" {
    37  		t.Fatal("azure tenant ID not set")
    38  	}
    39  	if azureClientID == "" {
    40  		t.Fatal("azure client ID not set")
    41  	}
    42  	if azureClientSecret == "" {
    43  		t.Fatal("azure client secret not set")
    44  	}
    45  	if gcpEmail == "" {
    46  		t.Fatal("GCP email not set")
    47  	}
    48  	if gcpPrivateKey == "" {
    49  		t.Fatal("GCP private key not set")
    50  	}
    51  }
    52  
    53  func TestClientSideEncryptionSpec(t *testing.T) {
    54  	verifyClientSideEncryptionVarsSet(t)
    55  
    56  	for _, fileName := range jsonFilesInDir(t, path.Join(dataPath, encryptionSpecName)) {
    57  		t.Run(fileName, func(t *testing.T) {
    58  			re := regexp.MustCompile(`fle2\-Range\-.*\-Correctness`)
    59  			if re.Match([]byte(fileName)) {
    60  				t.Skipf("skipping test on macOS due to slow runtime")
    61  			}
    62  			if fileName == "kmipKMS.json" && "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
    63  				t.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
    64  			}
    65  			runSpecTestFile(t, encryptionSpecName, fileName)
    66  		})
    67  	}
    68  }
    69  

View as plain text