-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_context_test.go
37 lines (27 loc) · 952 Bytes
/
auth_context_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
package main
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParsePrivateKeyFile(t *testing.T) {
pkBytes := toPEM(genPrivateKey(t))
creds, err := fromPrivateKey("random", pkBytes, "")
assert.NoError(t, err)
assert.NotNil(t, creds, "Creds should be parsed")
assert.Equal(t, "random", creds.UID, "UID not equal")
}
func TestParsePrincipalSecretFile(t *testing.T) {
pkBytes := toPEM(genPrivateKey(t))
_json := make(map[string]interface{})
_json["login_endpoint"] = "http://login-here.com"
_json["uid"] = "random"
_json["private_key"] = string(pkBytes)
jsonBytes, _ := json.Marshal(_json)
creds, err := fromPrincipalSecret(jsonBytes)
assert.NoError(t, err)
assert.NotNil(t, creds, "Creds should be parsed")
assert.Equal(t, "random", creds.UID, "UID not equal")
assert.Equal(t, "http://login-here.com", creds.AuthEndpoint)
assert.NotNil(t, creds.PrivateKey, "Private key should be parsed")
}