-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathclient_secret_rotation_test.go
More file actions
45 lines (38 loc) · 1.03 KB
/
client_secret_rotation_test.go
File metadata and controls
45 lines (38 loc) · 1.03 KB
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
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package client
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClient_GetRotatedHashes(t *testing.T) {
t.Run("returns nil when no rotated secrets", func(t *testing.T) {
c := &Client{
RotatedSecrets: "",
}
hashes := c.GetRotatedHashes()
assert.Nil(t, hashes)
})
t.Run("returns hashes when rotated secrets exist", func(t *testing.T) {
secrets := []string{"hash1", "hash2", "hash3"}
secretsJSON, err := json.Marshal(secrets)
require.NoError(t, err)
c := &Client{
RotatedSecrets: string(secretsJSON),
}
hashes := c.GetRotatedHashes()
require.Len(t, hashes, 3)
assert.Equal(t, []byte("hash1"), hashes[0])
assert.Equal(t, []byte("hash2"), hashes[1])
assert.Equal(t, []byte("hash3"), hashes[2])
})
t.Run("returns nil on invalid JSON", func(t *testing.T) {
c := &Client{
RotatedSecrets: "invalid json",
}
hashes := c.GetRotatedHashes()
assert.Nil(t, hashes)
})
}