From 00174851630da7fe21ab8ad52b9dd260d7190b27 Mon Sep 17 00:00:00 2001 From: Martin Wentzel Date: Thu, 22 Dec 2022 14:49:05 +0100 Subject: [PATCH] tests: Add test for parsing auth headers. --- .../provider/authentication_helpers_test.go | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/provider/authentication_helpers_test.go b/internal/provider/authentication_helpers_test.go index 8f51d18f..fef82429 100644 --- a/internal/provider/authentication_helpers_test.go +++ b/internal/provider/authentication_helpers_test.go @@ -1,6 +1,8 @@ package provider -import "testing" +import ( + "testing" +) func TestIsECRRepositoryURL(t *testing.T) { @@ -17,3 +19,19 @@ func TestIsECRRepositoryURL(t *testing.T) { t.Fatalf("Expected true") } } + +func TestParseAuthHeaders(t *testing.T) { + header := "Bearer realm=\"https://gcr.io/v2/token\",service=\"gcr.io\",scope=\"repository:/:/:pull\"" + result := parseAuthHeader(header) + wantScope := "repository:/:/: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:/:/:push,pull\"" + result = parseAuthHeader(header) + wantScope = "repository:/:/:push,pull" + if result["scope"] != wantScope { + t.Errorf("want: %#v, got: %#v", wantScope, result["scope"]) + } +}