forked from microsoft/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alwaysencrypted_akv_test.go
54 lines (44 loc) · 1.15 KB
/
alwaysencrypted_akv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build go1.18
// +build go1.18
package mssql
import (
"testing"
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys"
"github.com/microsoft/go-mssqldb/aecmk"
"github.com/microsoft/go-mssqldb/aecmk/akv"
"github.com/microsoft/go-mssqldb/internal/akvkeys"
"github.com/stretchr/testify/assert"
)
type akvProviderTest struct {
client *azkeys.Client
keyName string
}
func (p *akvProviderTest) ProvisionMasterKey(t *testing.T) string {
t.Helper()
client, vaultURL, err := akvkeys.GetTestAKV()
if err != nil {
t.Skip("Unable to access AKV")
}
name, err := akvkeys.CreateRSAKey(client)
assert.NoError(t, err, "CreateRSAKey")
keyPath := vaultURL + "/" + name
p.client = client
p.keyName = name
return keyPath
}
func (p *akvProviderTest) DeleteMasterKey(t *testing.T) {
t.Helper()
if !akvkeys.DeleteRSAKey(p.client, p.keyName) {
assert.Fail(t, "DeleteRSAKey failed")
}
}
func (p *akvProviderTest) GetProvider(t *testing.T) aecmk.ColumnEncryptionKeyProvider {
t.Helper()
return &akv.KeyProvider
}
func (p *akvProviderTest) Name() string {
return aecmk.AzureKeyVaultKeyProvider
}
func init() {
addProviderTest(&akvProviderTest{})
}