Skip to content

Commit

Permalink
Fix encryption keys list call (WIP, still needs test recordings)
Browse files Browse the repository at this point in the history
  • Loading branch information
acwest committed Sep 19, 2024
1 parent 86c7e2f commit e9c9036
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
10 changes: 2 additions & 8 deletions management/encryption_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import (
"time"
)

// EncryptionKeyList is a list of encryption keys.
type EncryptionKeyList struct {
List
Keys []*EncryptionKey `json:"keys"`
}

// EncryptionKey is used for encrypting data.
type EncryptionKey struct {
// Key ID
Expand Down Expand Up @@ -70,8 +64,8 @@ func (m *EncryptionKeyManager) Create(ctx context.Context, e *EncryptionKey, opt
// List all encryption keys.
//
// See: https://auth0.com/docs/api/management/v2/keys/get-encryption-keys
func (m *EncryptionKeyManager) List(ctx context.Context, opts ...RequestOption) (ekl *EncryptionKeyList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("keys", "encryption"), &ekl, applyListDefaults(opts))
func (m *EncryptionKeyManager) List(ctx context.Context, opts ...RequestOption) (keys []*EncryptionKey, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("keys", "encryption"), &keys, opts...)
return
}

Expand Down
18 changes: 9 additions & 9 deletions management/encryption_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func TestEncryptionKeyManager_Create(t *testing.T) {
func TestEncryptionKeyManager_List(t *testing.T) {
configureHTTPTestRecordings(t)
key := givenEncryptionKey(t)
keyList, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
keys, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
assert.NoError(t, err)
assert.Contains(t, keyList.Keys, key)
assert.Contains(t, keys, key)
}

func TestEncryptionKeyManager_Read(t *testing.T) {
Expand All @@ -64,12 +64,12 @@ func TestEncryptionKeyManager_Read(t *testing.T) {

func TestEncryptionKeyManager_Rekey(t *testing.T) {
configureHTTPTestRecordings(t)
oldKeyList, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
oldKeys, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
assert.NoError(t, err)
assert.NotEmpty(t, oldKeyList.Keys)
assert.NotEmpty(t, oldKeys)

var oldKey, newKey *EncryptionKey
for _, key := range oldKeyList.Keys {
for _, key := range oldKeys {
if key.GetState() == "active" && key.GetType() == "tenant-master-key" {
oldKey = key
break
Expand All @@ -80,11 +80,11 @@ func TestEncryptionKeyManager_Rekey(t *testing.T) {
err = api.EncryptionKey.Rekey(context.Background())
assert.NoError(t, err)

keyList, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
keys, err := api.EncryptionKey.List(context.Background(), PerPage(50), Page(0))
assert.NoError(t, err)
assert.NotEmpty(t, keyList.Keys)
assert.NotEmpty(t, keys)

for _, key := range keyList.Keys {
for _, key := range keys {
if key.GetState() == "active" && key.GetType() == "tenant-master-key" {
newKey = key
break
Expand All @@ -93,7 +93,7 @@ func TestEncryptionKeyManager_Rekey(t *testing.T) {
assert.NotNil(t, newKey)

assert.NotEqual(t, oldKey.GetKID(), newKey.GetKID())
assert.NotEqual(t, keyList.Keys, oldKeyList.Keys)
assert.NotEqual(t, keys, oldKeys)
}

func TestEncryptionKeyManager_Delete(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9c9036

Please sign in to comment.