-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage_test.go
More file actions
103 lines (93 loc) · 2.31 KB
/
storage_test.go
File metadata and controls
103 lines (93 loc) · 2.31 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package mfa
import (
"context"
"os"
"testing"
"github.com/aws/aws-sdk-go-v2/config"
)
const TestTableName = "WebAuthn"
func (ms *MfaSuite) TestStorage_StoreLoad() {
type fields struct {
Table string
AwsEndpoint string
AwsRegion string
PrimaryKeyAttribute string
}
type args struct {
key string
item any
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "simple test",
fields: fields{
Table: TestTableName,
AwsEndpoint: os.Getenv("AWS_ENDPOINT"),
AwsRegion: os.Getenv("AWS_DEFAULT_REGION"),
PrimaryKeyAttribute: "uuid",
},
args: args{
key: "2B28BED1-1225-4EC9-98F9-EAB8FBCEDBA0",
item: &WebauthnUser{
ID: "2B28BED1-1225-4EC9-98F9-EAB8FBCEDBA0",
Name: "test_user",
DisplayName: "Test User",
},
},
wantErr: false,
},
}
for _, tt := range tests {
ms.T().Run(tt.name, func(t *testing.T) {
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion(tt.fields.AwsRegion),
config.WithBaseEndpoint(tt.fields.AwsEndpoint),
)
ms.NoError(err)
s, err := NewStorage(cfg)
ms.NoError(err)
err = s.Store(tt.fields.Table, tt.args.item)
if tt.wantErr {
ms.Error(err, "didn't get an expected error Store()")
return
}
ms.NoError(err, "unexpected error with Store()")
var user WebauthnUser
ms.NoError(s.Load(tt.fields.Table, "uuid", tt.args.key, &user), "error with s.Load()")
ms.Equal(tt.args.key, user.ID, "incorrect user.ID")
})
}
}
func (ms *MfaSuite) TestStorageScanApiKey() {
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion("local"),
config.WithBaseEndpoint(os.Getenv("AWS_ENDPOINT")),
)
ms.NoError(err)
s, err := NewStorage(cfg)
ms.NoError(err)
must(s.Store(TestTableName, &WebauthnUser{
ID: "user1",
ApiKeyValue: "key1",
EncryptedAppId: "xyz123",
}))
must(s.Store(TestTableName, &WebauthnUser{
ID: "user2",
ApiKeyValue: "key2",
EncryptedAppId: "abc123",
}))
var users []WebauthnUser
err = s.ScanApiKey(TestTableName, "key1", &users)
ms.NoError(err)
ms.Len(users, 1)
ms.Equal("user1", users[0].ID)
ms.Equal("key1", users[0].ApiKeyValue)
ms.Equal("xyz123", users[0].EncryptedAppId)
}