-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read access token to use it in authentication. (#12123)
* Read access token to use it in authentication. * Extract building new authenticator to separate function. The authenticator passed to the sync function already contains key or token. * formating * Log finished important steps * Add suite test file to have only one entry point in to tests. * Added missing suite test file.
- Loading branch information
Showing
7 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestImageSyncer(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "ImageSyncer Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/go-containerregistry/pkg/authn" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("newAuthenticator", func() { | ||
var cfg Config | ||
|
||
BeforeEach(func() { | ||
cfg = Config{} | ||
}) | ||
|
||
Context("when TargetKeyFile is provided", func() { | ||
It("should create a basic authenticator", func() { | ||
cfg.TargetKeyFile = "./test-fixtures/keyfile.json" | ||
auth, err := cfg.newAuthenticator() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(auth).To(Equal(&authn.Basic{ | ||
Username: "_json_key", | ||
Password: "test_content", | ||
})) | ||
}) | ||
|
||
It("should return an error if the key file cannot be read", func() { | ||
cfg.TargetKeyFile = "./test-fixtures/invalid_keyfile.json" | ||
auth, err := cfg.newAuthenticator() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(auth).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Context("when AccessToken is provided", func() { | ||
It("should create a bearer authenticator", func() { | ||
cfg.AccessToken = "valid-access-token" | ||
auth, err := cfg.newAuthenticator() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(auth).To(Equal(&authn.Bearer{ | ||
Token: "valid-access-token", | ||
})) | ||
}) | ||
}) | ||
|
||
Context("when neither TargetKeyFile nor AccessToken is provided", func() { | ||
It("should return an error", func() { | ||
cfg.TargetKeyFile = "" | ||
cfg.AccessToken = "" | ||
auth, err := cfg.newAuthenticator() | ||
Expect(err).To(HaveOccurred()) | ||
Expect(auth).To(BeNil()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters