forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcredentials_test.go
More file actions
98 lines (74 loc) · 2.61 KB
/
credentials_test.go
File metadata and controls
98 lines (74 loc) · 2.61 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package core
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
const (
Token string = "sampleToken"
AwsKey string = "sampleKey"
AwsSecret string = "sampleSecret"
AwsSession string = "sampleSession"
)
func TestGetSetCredentialsHappy(t *testing.T) {
credentialsService := NewCredentialsService()
credentialsService.SetCredentials(Token, AwsKey, AwsSecret, AwsSession)
credentials, err := credentialsService.GetCredentials(Token)
assert.NoError(t, err)
assert.Equal(t, AwsKey, credentials.AwsKey)
assert.Equal(t, AwsSecret, credentials.AwsSecret)
assert.Equal(t, AwsSession, credentials.AwsSession)
}
func TestGetCredentialsFail(t *testing.T) {
credentialsService := NewCredentialsService()
_, err := credentialsService.GetCredentials("unknownToken")
assert.Error(t, err)
}
func TestUpdateCredentialsHappy(t *testing.T) {
credentialsService := NewCredentialsService()
credentialsService.SetCredentials(Token, AwsKey, AwsSecret, AwsSession)
err := credentialsService.UpdateCredentials("sampleKey1", "sampleSecret1", "sampleSession1")
assert.NoError(t, err)
credentials, err := credentialsService.GetCredentials(Token)
assert.NoError(t, err)
assert.Equal(t, "sampleKey1", credentials.AwsKey)
assert.Equal(t, "sampleSecret1", credentials.AwsSecret)
assert.Equal(t, "sampleSession1", credentials.AwsSession)
}
func TestUpdateCredentialsFail(t *testing.T) {
credentialsService := NewCredentialsService()
err := credentialsService.UpdateCredentials("unknownKey", "unknownSecret", "unknownSession")
assert.Error(t, err)
}
func TestUpdateCredentialsOfBlockedService(t *testing.T) {
credentialsService := NewCredentialsService()
credentialsService.BlockService()
credentialsService.SetCredentials(Token, AwsKey, AwsSecret, AwsSession)
err := credentialsService.UpdateCredentials("sampleKey1", "sampleSecret1", "sampleSession1")
assert.NoError(t, err)
}
func TestConsecutiveBlockService(t *testing.T) {
credentialsService := NewCredentialsService()
timeout := time.After(1 * time.Second)
done := make(chan bool)
go func() {
for i := 0; i < 10; i++ {
credentialsService.BlockService()
}
done <- true
}()
select {
case <-timeout:
t.Fatal("BlockService should not block the calling thread.")
case <-done:
}
}
// unlocking a mutex twice causes panic
// the assertion here is basically not having panic
func TestConsecutiveUnblockService(t *testing.T) {
credentialsService := NewCredentialsService()
credentialsService.UnblockService()
credentialsService.UnblockService()
}