-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathcredentials_test.go
More file actions
71 lines (49 loc) · 2.03 KB
/
credentials_test.go
File metadata and controls
71 lines (49 loc) · 2.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
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package core
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
const (
Token string = "sampleToken"
AwsKey string = "sampleKey"
AwsSecret string = "sampleSecret"
AwsSession string = "sampleSession"
)
func TestGetSetCredentialsHappy(t *testing.T) {
credentialsService := NewCredentialsService()
credentialsExpiration := time.Now().Add(15 * time.Minute)
credentialsService.SetCredentials(Token, AwsKey, AwsSecret, AwsSession, credentialsExpiration)
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()
credentialsExpiration := time.Now().Add(15 * time.Minute)
credentialsService.SetCredentials(Token, AwsKey, AwsSecret, AwsSession, credentialsExpiration)
restoreCredentialsExpiration := time.Now().Add(10 * time.Hour)
err := credentialsService.UpdateCredentials("sampleKey1", "sampleSecret1", "sampleSession1", restoreCredentialsExpiration)
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)
nineHoursLater := time.Now().Add(9 * time.Hour)
assert.True(t, nineHoursLater.Before(credentials.Expiration))
}
func TestUpdateCredentialsFail(t *testing.T) {
credentialsService := NewCredentialsService()
err := credentialsService.UpdateCredentials("unknownKey", "unknownSecret", "unknownSession", time.Now())
assert.Error(t, err)
}