Skip to content

Commit

Permalink
Added unit test for WithAuth KO case
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Salerno <[email protected]>
  • Loading branch information
davidesalerno committed Jun 28, 2023
1 parent f66f0b9 commit 8e54e79
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions modules/dockerregistry/dockerregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func TestDockerRegistryWithData(t *testing.T) {
t.Cleanup(cancel)
}

/**/

func TestDockerRegistryWithAuth(t *testing.T) {
ctx := context.Background()
wd, err := os.Getwd()
Expand Down Expand Up @@ -141,6 +139,35 @@ func TestDockerRegistryWithAuth(t *testing.T) {
t.Cleanup(cancel)
}

func TestDockerRegistryWithAuthWithUnauthorizedRequest(t *testing.T) {
ctx := context.Background()
wd, err := os.Getwd()
assert.NoError(t, err)
container, err := RunContainer(ctx, WithAuthentication(wd+"/../../testdata/auth"))

if err != nil {
t.Fatal(err)
}

// Clean up the container after the test is complete
t.Cleanup(func() {
if err := container.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

port, ipAddress := getRegistryPortAndAddress(t, err, container, ctx)

// Let's simply check that the registry is up and running with a GET to http://localhost:5000/v2/_catalog
h := http.Client{}
req, _ := http.NewRequest("GET", "http://"+ipAddress+":"+port.Port()+"/v2/_catalog", nil)
resp, err := h.Do(req)
require.Equal(t, resp.StatusCode, 401)
defer resp.Body.Close()
_, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
}

func TestDockerRegistryWithAuthAndData(t *testing.T) {
t.Cleanup(func() {
os.Setenv("DOCKER_AUTH_CONFIG", originalDockerAuthConfig)
Expand Down

0 comments on commit 8e54e79

Please sign in to comment.