-
Notifications
You must be signed in to change notification settings - Fork 24
chore(Issue 78): integration tests for key_access_server registry db interactions #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakedoublev
merged 14 commits into
policy-config-changes
from
issue-78/kas-registry-tests
Jan 31, 2024
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cbce01e
remove name from resource mapping in ER diagram
jakedoublev 57b0e3f
resource mappings test suite WIP
jakedoublev ba74049
remove extraneous test file for subject-mappings that is not in integ…
jakedoublev 1a50841
properly handle nil metadata in resource mapping
jakedoublev bf77fa5
finish integration test suite for resource mappings
jakedoublev 439805e
Merge branch 'policy-config-changes' into issue-77/resource-map-tests
jakedoublev bb270c2
kas registry integration tests WIP with working remote public keys an…
jakedoublev fe286e5
working kas registry integration test LISTs with remote and local pub…
jakedoublev a362ddd
do not require optional metadata
jakedoublev 9764dca
KAS registry test suite
jakedoublev a80a3b6
Merge branch 'policy-config-changes' into issue-78/kas-registry-tests
jakedoublev 5f2b180
fix duplicate KAS names in tests causing test failure due to unique c…
jakedoublev 8bfecfa
use key_access_server field instead of name within key_access_server …
jakedoublev 439feef
comprehensively rename table key_access_server column key_access_serv…
jakedoublev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,245 @@ | ||
| package integration | ||
|
|
||
| import ( | ||
| "context" | ||
| "log/slog" | ||
| "testing" | ||
|
|
||
| "github.com/opentdf/opentdf-v2-poc/sdk/common" | ||
| kasr "github.com/opentdf/opentdf-v2-poc/sdk/kasregistry" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| var nonExistentKasRegistryId = "78909865-8888-9999-9999-000000654321" | ||
|
|
||
| type KasRegistrySuite struct { | ||
| suite.Suite | ||
| schema string | ||
| f Fixtures | ||
| db DBInterface | ||
| ctx context.Context | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) SetupSuite() { | ||
| slog.Info("setting up db.KasRegistry test suite") | ||
| s.ctx = context.Background() | ||
| s.schema = "test_opentdf_kas_registry" | ||
| s.db = NewDBInterface(s.schema) | ||
| s.f = NewFixture(s.db) | ||
| s.f.Provision() | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) TearDownSuite() { | ||
| slog.Info("tearing down db.KasRegistry test suite") | ||
| s.f.TearDown() | ||
| } | ||
|
|
||
| func getKasRegistryFixtures() []FixtureDataKasRegistry { | ||
| return []FixtureDataKasRegistry{ | ||
| fixtures.GetKasRegistryKey("key_access_server_1"), | ||
| fixtures.GetKasRegistryKey("key_access_server_2"), | ||
| } | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_ListKeyAccessServers() { | ||
| fixtures := getKasRegistryFixtures() | ||
| list, err := s.db.Client.ListKeyAccessServers(s.ctx) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), list) | ||
| for _, fixture := range fixtures { | ||
| for _, item := range list { | ||
| if item.Id == fixture.Id { | ||
| assert.Equal(s.T(), fixture.Id, item.Id) | ||
| if item.PublicKey.GetRemote() != "" { | ||
| assert.Equal(s.T(), fixture.PubKey.Remote, item.PublicKey.GetRemote()) | ||
| } else { | ||
| assert.Equal(s.T(), fixture.PubKey.Local, item.PublicKey.GetLocal()) | ||
| } | ||
| assert.Equal(s.T(), fixture.KeyAccessServer, item.KeyAccessServer) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_GetKeyAccessServer() { | ||
| remoteFixture := fixtures.GetKasRegistryKey("key_access_server_1") | ||
| localFixture := fixtures.GetKasRegistryKey("key_access_server_2") | ||
|
|
||
| remote, err := s.db.Client.GetKeyAccessServer(s.ctx, remoteFixture.Id) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), remote) | ||
| assert.Equal(s.T(), remoteFixture.Id, remote.Id) | ||
| assert.Equal(s.T(), remoteFixture.KeyAccessServer, remote.KeyAccessServer) | ||
| assert.Equal(s.T(), remoteFixture.PubKey.Remote, remote.PublicKey.GetRemote()) | ||
|
|
||
| local, err := s.db.Client.GetKeyAccessServer(s.ctx, localFixture.Id) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), local) | ||
| assert.Equal(s.T(), localFixture.Id, local.Id) | ||
| assert.Equal(s.T(), localFixture.KeyAccessServer, local.KeyAccessServer) | ||
| assert.Equal(s.T(), localFixture.PubKey.Local, local.PublicKey.GetLocal()) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_GetKeyAccessServerWithNonExistentIdFails() { | ||
| resp, err := s.db.Client.GetKeyAccessServer(s.ctx, nonExistentKasRegistryId) | ||
| assert.NotNil(s.T(), err) | ||
| assert.Nil(s.T(), resp) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_CreateKeyAccessServer_Remote() { | ||
| metadata := &common.MetadataMutable{ | ||
| Labels: map[string]string{ | ||
| "name": "this is the test name of my key access server", | ||
| }, | ||
| Description: "test create key access server description", | ||
| } | ||
|
|
||
| pubKey := &kasr.PublicKey{ | ||
| PublicKey: &kasr.PublicKey_Remote{ | ||
| Remote: "https://remote.com/key", | ||
| }, | ||
| } | ||
|
|
||
| kasRegistry := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "test create key access server", | ||
| PublicKey: pubKey, | ||
| Metadata: metadata, | ||
| } | ||
| createdKasRegistry, err := s.db.Client.CreateKeyAccessServer(s.ctx, kasRegistry) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), createdKasRegistry) | ||
| assert.Equal(s.T(), kasRegistry.KeyAccessServer, createdKasRegistry.KeyAccessServer) | ||
| assert.Equal(s.T(), kasRegistry.PublicKey.GetRemote(), createdKasRegistry.PublicKey.GetRemote()) | ||
| assert.Equal(s.T(), createdKasRegistry.PublicKey.GetLocal(), "") | ||
| assert.Equal(s.T(), kasRegistry.Metadata.Description, createdKasRegistry.Metadata.Description) | ||
| assert.EqualValues(s.T(), kasRegistry.Metadata.Labels, createdKasRegistry.Metadata.Labels) | ||
| assert.NotEqual(s.T(), "", createdKasRegistry.Id) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_CreateKeyAccessServer_Local() { | ||
| metadata := &common.MetadataMutable{ | ||
| Labels: map[string]string{ | ||
| "name": "local KAS", | ||
| }, | ||
| Description: "this KAS has a locally provided key", | ||
| } | ||
|
|
||
| pubKey := &kasr.PublicKey{ | ||
| PublicKey: &kasr.PublicKey_Local{ | ||
| Local: "some_local_public_key_in_base64", | ||
| }, | ||
| } | ||
|
|
||
| kasRegistry := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "testing creation with local key", | ||
| PublicKey: pubKey, | ||
| Metadata: metadata, | ||
| } | ||
| createdKasRegistry, err := s.db.Client.CreateKeyAccessServer(s.ctx, kasRegistry) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), createdKasRegistry) | ||
| assert.Equal(s.T(), kasRegistry.KeyAccessServer, createdKasRegistry.KeyAccessServer) | ||
| assert.Equal(s.T(), kasRegistry.PublicKey.GetLocal(), createdKasRegistry.PublicKey.GetLocal()) | ||
| assert.Equal(s.T(), createdKasRegistry.PublicKey.GetRemote(), "") | ||
| assert.Equal(s.T(), kasRegistry.Metadata.Description, createdKasRegistry.Metadata.Description) | ||
| assert.EqualValues(s.T(), kasRegistry.Metadata.Labels, createdKasRegistry.Metadata.Labels) | ||
| assert.NotEqual(s.T(), "", createdKasRegistry.Id) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_UpdateKeyAccessServer() { | ||
| // create a test KAS | ||
| pubKey := &kasr.PublicKey{ | ||
| PublicKey: &kasr.PublicKey_Remote{ | ||
| Remote: "https://remote.com/key", | ||
| }, | ||
| } | ||
| testKas := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "testing update with remote key", | ||
| PublicKey: pubKey, | ||
| } | ||
| createdKas, err := s.db.Client.CreateKeyAccessServer(s.ctx, testKas) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), createdKas) | ||
|
|
||
| // update it with new values and metadata | ||
| updatedMetadata := &common.MetadataMutable{ | ||
| Labels: map[string]string{ | ||
| "name": "updated name", | ||
| }, | ||
| Description: "updated description", | ||
| } | ||
| updatedKas := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "updated name", | ||
| PublicKey: pubKey, | ||
| Metadata: updatedMetadata, | ||
| } | ||
| updated, err := s.db.Client.UpdateKeyAccessServer(s.ctx, createdKas.Id, updatedKas) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), updated) | ||
|
|
||
| // get after update to validate changes were successful | ||
| got, err := s.db.Client.GetKeyAccessServer(s.ctx, createdKas.Id) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), got) | ||
| assert.Equal(s.T(), createdKas.Id, got.Id) | ||
| assert.Equal(s.T(), updatedKas.KeyAccessServer, got.KeyAccessServer) | ||
| assert.Equal(s.T(), updatedKas.PublicKey.GetRemote(), got.PublicKey.GetRemote()) | ||
| assert.Equal(s.T(), updatedMetadata.Description, got.Metadata.Description) | ||
| assert.EqualValues(s.T(), updatedMetadata.Labels, got.Metadata.Labels) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_UpdateKeyAccessServerWithNonExistentIdFails() { | ||
| pubKey := &kasr.PublicKey{ | ||
| PublicKey: &kasr.PublicKey_Local{ | ||
| Local: "this_is_a_local_key", | ||
| }, | ||
| } | ||
| updatedKas := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "some name", | ||
| PublicKey: pubKey, | ||
| } | ||
| resp, err := s.db.Client.UpdateKeyAccessServer(s.ctx, nonExistentKasRegistryId, updatedKas) | ||
| assert.NotNil(s.T(), err) | ||
jrschumacher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.Nil(s.T(), resp) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_DeleteKeyAccessServer() { | ||
| // create a test KAS | ||
| pubKey := &kasr.PublicKey{ | ||
| PublicKey: &kasr.PublicKey_Remote{ | ||
| Remote: "https://remote.com/key", | ||
| }, | ||
| } | ||
| testKas := &kasr.KeyAccessServerCreateUpdate{ | ||
| KeyAccessServer: "test delete", | ||
| PublicKey: pubKey, | ||
| } | ||
| createdKas, err := s.db.Client.CreateKeyAccessServer(s.ctx, testKas) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), createdKas) | ||
|
|
||
| // delete it | ||
| deleted, err := s.db.Client.DeleteKeyAccessServer(s.ctx, createdKas.Id) | ||
| assert.Nil(s.T(), err) | ||
| assert.NotNil(s.T(), deleted) | ||
|
|
||
| // get after delete to validate it's gone | ||
| resp, err := s.db.Client.GetKeyAccessServer(s.ctx, createdKas.Id) | ||
| assert.NotNil(s.T(), err) | ||
| assert.Nil(s.T(), resp) | ||
| } | ||
|
|
||
| func (s *KasRegistrySuite) Test_DeleteKeyAccessServerWithNonExistentIdFails() { | ||
| resp, err := s.db.Client.DeleteKeyAccessServer(s.ctx, nonExistentKasRegistryId) | ||
| assert.NotNil(s.T(), err) | ||
| assert.Nil(s.T(), resp) | ||
| } | ||
|
|
||
| func TestKasRegistrySuite(t *testing.T) { | ||
| if testing.Short() { | ||
| t.Skip("skipping db.KasRegistry integration tests") | ||
| } | ||
| suite.Run(t, new(KasRegistrySuite)) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.