mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-18 23:06:10 -05:00
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIsECRPublicRepositoryURL(t *testing.T) {
|
|
if !isECRPublicRepositoryURL("public.ecr.aws") {
|
|
t.Fatalf("Expected true")
|
|
}
|
|
if isECRPublicRepositoryURL("public.ecr.aws.com") {
|
|
t.Fatalf("Expected false")
|
|
}
|
|
}
|
|
|
|
func TestIsECRRepositoryURL(t *testing.T) {
|
|
if !isECRRepositoryURL("2385929435838.dkr.ecr.eu-central-1.amazonaws.com") {
|
|
t.Fatalf("Expected true")
|
|
}
|
|
if !isECRRepositoryURL("39e39fmgvkgd.dkr.ecr.us-east-1.amazonaws.com") {
|
|
t.Fatalf("Expected true")
|
|
}
|
|
if isECRRepositoryURL("39e39fmgvkgd.dkr.ecrus-east-1.amazonaws.com") {
|
|
t.Fatalf("Expected false")
|
|
}
|
|
if !isECRRepositoryURL("public.ecr.aws") {
|
|
t.Fatalf("Expected true")
|
|
}
|
|
}
|
|
|
|
func TestParseAuthHeaders(t *testing.T) {
|
|
_, err := parseAuthHeader("")
|
|
if err == nil || err.Error() != "missing or invalid www-authenticate header, does not start with 'Bearer'" {
|
|
t.Fatalf("wanted \"missing or invalid www-authenticate header, does not start with 'Bearer'\", got nil")
|
|
}
|
|
|
|
header := "Bearer realm=\"https://gcr.io/v2/token\",service=\"gcr.io\",scope=\"repository:<owner>/:<repo>/<name>:pull\""
|
|
result, err := parseAuthHeader(header)
|
|
if err != nil {
|
|
t.Errorf("wanted no error, got %s", err)
|
|
}
|
|
wantScope := "repository:<owner>/:<repo>/<name>:pull"
|
|
if result["scope"] != wantScope {
|
|
t.Errorf("want: %#v, got: %#v", wantScope, result["scope"])
|
|
}
|
|
|
|
header = "Bearer realm=\"https://gcr.io/v2/token\",service=\"gcr.io\",scope=\"repository:<owner>/:<repo>/<name>:push,pull\""
|
|
result, err = parseAuthHeader(header)
|
|
if err != nil {
|
|
t.Errorf("wanted no error, got %s", err)
|
|
}
|
|
wantScope = "repository:<owner>/:<repo>/<name>:push,pull"
|
|
if result["scope"] != wantScope {
|
|
t.Errorf("want: %#v, got: %#v", wantScope, result["scope"])
|
|
}
|
|
}
|