-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth_test.go
More file actions
42 lines (39 loc) · 886 Bytes
/
auth_test.go
File metadata and controls
42 lines (39 loc) · 886 Bytes
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
package main
import (
"testing"
"github.com/docker/distribution/reference"
"github.com/stretchr/testify/require"
)
func TestAuthParse(t *testing.T) {
var auth = `
{
"auths": {
"16371954.dkr.ecr.us-east-1.amazonaws.com": {
"auth": "YWFhOmFhYQo="
},
"docker.io": {
"auth": "eXl5Onl5eQo="
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.12-ce (linux)"
}
}
`
for _, tst := range []struct {
ref string
expected string
}{
{ref: "16371954.dkr.ecr.us-east-1.amazonaws.com/user/project/server", expected: "aaa"},
{ref: "user/project/server", expected: "yyy"},
} {
named, err := reference.ParseAnyReference(tst.ref)
require.NoError(t, err)
t.Logf("Reference: +%v", named)
authKey, err := parseDefaultAuth(named, []byte(auth))
if err != nil {
require.Fail(t, err.Error())
}
require.Equal(t, tst.expected, authKey.Username)
}
}