2022-05-25 09:03:36 +00:00
|
|
|
package registryclient
|
|
|
|
|
|
|
|
import (
|
2023-09-20 05:29:20 +00:00
|
|
|
"context"
|
2022-05-25 09:03:36 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Make sure that client conforms Client interface.
|
|
|
|
var _ Client = &client{}
|
|
|
|
|
|
|
|
func TestInitClientWithEmptyOptions(t *testing.T) {
|
2022-12-07 15:08:37 +00:00
|
|
|
c, err := New()
|
2022-05-25 09:03:36 +00:00
|
|
|
assert.NilError(t, err)
|
2022-12-09 09:09:11 +00:00
|
|
|
assert.Assert(t, defaultTransport == c.getTransport())
|
2023-02-20 16:26:10 +00:00
|
|
|
assert.Assert(t, c.Keychain() != nil)
|
2022-05-25 09:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInitClientWithInsecureRegistryOption(t *testing.T) {
|
|
|
|
expClient := &client{
|
|
|
|
transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
|
|
|
|
}
|
2022-12-07 15:08:37 +00:00
|
|
|
c, err := New(WithAllowInsecureRegistry())
|
2022-12-09 09:09:11 +00:00
|
|
|
expInsecureSkipVerify := expClient.transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify
|
2022-12-07 15:08:37 +00:00
|
|
|
gotInsecureSkipVerify := c.getTransport().(*http.Transport).TLSClientConfig.InsecureSkipVerify
|
2022-05-25 09:03:36 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, expInsecureSkipVerify == gotInsecureSkipVerify)
|
2023-02-20 16:26:10 +00:00
|
|
|
assert.Assert(t, c.Keychain() != nil)
|
2022-05-25 09:03:36 +00:00
|
|
|
}
|
2023-09-20 05:29:20 +00:00
|
|
|
|
|
|
|
func TestFetchImageDescriptor(t *testing.T) {
|
|
|
|
c, err := New()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
tagDesc, err := c.FetchImageDescriptor(context.Background(), "ghcr.io/kyverno/test-verify-image:signed-keyless")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, tagDesc.Digest.String(), "sha256:445a99db22e9add9bfb15ddb1980861a329e5dff5c88d7eec9cbf08b6b2f4eb1")
|
|
|
|
|
|
|
|
digestDesc, err := c.FetchImageDescriptor(context.Background(), "ghcr.io/kyverno/test-verify-image@sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, digestDesc.Digest.String(), "sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105")
|
|
|
|
}
|