forked from sendgridlabs/go-kinesis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth_test.go
80 lines (63 loc) · 1.98 KB
/
auth_test.go
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
package kinesis
import (
"os"
"testing"
)
func TestAuthInterfaceIsImplemented(t *testing.T) {
var auth Auth = &AuthCredentials{}
if auth == nil {
t.Error("Invalid nil auth credentials value")
}
}
func TestGetSecretKey(t *testing.T) {
auth := NewAuth("BAD_ACCESS_KEY", "BAD_SECRET_KEY", "BAD_SECURITY_TOKEN")
if auth.GetAccessKey() != "BAD_ACCESS_KEY" {
t.Error("incorrect value for auth#accessKey")
}
}
func TestGetAccessKey(t *testing.T) {
auth := NewAuth("BAD_ACCESS_KEY", "BAD_SECRET_KEY", "BAD_SECURITY_TOKEN")
if auth.GetSecretKey() != "BAD_SECRET_KEY" {
t.Error("incorrect value for auth#secretKey")
}
}
func TestGetToken(t *testing.T) {
auth := NewAuth("BAD_ACCESS_KEY", "BAD_SECRET_KEY", "BAD_SECURITY_TOKEN")
if auth.GetToken() != "BAD_SECURITY_TOKEN" {
t.Error("incorrect value for auth#token")
}
}
func TestNewAuthFromEnv(t *testing.T) {
os.Setenv(AccessEnvKey, "asdf")
os.Setenv(SecretEnvKey, "asdf2")
os.Setenv(SecurityTokenEnvKey, "dummy_token")
// Validate that the fallback environment variables will also work
defer os.Unsetenv(AccessEnvKey)
defer os.Unsetenv(SecretEnvKey)
defer os.Unsetenv(SecurityTokenEnvKey)
auth, _ := NewAuthFromEnv()
if auth.GetAccessKey() != "asdf" {
t.Error("Expected AccessKey to be inferred as \"asdf\"")
}
if auth.GetSecretKey() != "asdf2" {
t.Error("Expected SecretKey to be inferred as \"asdf2\"")
}
if auth.GetToken() != "dummy_token" {
t.Error("Expected SecretKey to be inferred as \"dummy_token\"")
}
}
func TestNewAuthFromEnvWithFallbackVars(t *testing.T) {
os.Setenv(AccessEnvKeyId, "asdf")
os.Setenv(SecretEnvAccessKey, "asdf2")
os.Setenv(SecurityTokenEnvKey, "dummy_token")
defer os.Unsetenv(AccessEnvKey)
defer os.Unsetenv(SecretEnvKey)
defer os.Unsetenv(SecurityTokenEnvKey)
auth, _ := NewAuthFromEnv()
if auth.GetAccessKey() != "asdf" {
t.Error("Expected AccessKey to be inferred as \"asdf\"")
}
if auth.GetSecretKey() != "asdf2" {
t.Error("Expected SecretKey to be inferred as \"asdf2\"")
}
}