Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sensor/common/registry/registry_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (rs *Store) UpsertRegistry(ctx context.Context, namespace, registry string,

regs := rs.getRegistries(namespace)
err = regs.UpdateImageIntegration(&storage.ImageIntegration{
Id: registry,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend letting UpdateImageIntegration set the registry as the ID automatically or validating it before persisting to avoid saving corrupted integrations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called in other places where the ID is already populated as a UUID. This is a case where we dont want to use a UUID because of how it's used. I think this is ok

Name: registry,
Type: "docker",
Categories: []storage.ImageIntegrationCategory{storage.ImageIntegrationCategory_REGISTRY},
Expand Down
61 changes: 61 additions & 0 deletions sensor/common/registry/registry_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package registry

import (
"context"
"testing"

"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/docker/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// alwaysInsecureCheckTLS is an implementation of registry.CheckTLS
// which always says the given address is insecure.
func alwaysInsecureCheckTLS(_ context.Context, _ string) (bool, error) {
return false, nil
}

func TestRegistryStore_same_namespace(t *testing.T) {
ctx := context.Background()

regStore := NewRegistryStore(alwaysInsecureCheckTLS)

dce := config.DockerConfigEntry{
Username: "username",
Password: "password",
}
require.NoError(t, regStore.UpsertRegistry(ctx, "qa", "image-registry.openshift-image-registry.svc:5000", dce))
require.NoError(t, regStore.UpsertRegistry(ctx, "qa", "image-registry.openshift-image-registry.svc.local:5000", dce))
require.NoError(t, regStore.UpsertRegistry(ctx, "qa", "172.99.12.11:5000", dce))

img := &storage.ImageName{
Registry: "image-registry.openshift-image-registry.svc:5000",
Remote: "qa/nginx",
Tag: "nginx:1.18.0",
FullName: "image-registry.openshift-image-registry.svc:5000/qa/nginx:1.18.0",
}
reg, err := regStore.GetRegistryForImage(img)
require.NoError(t, err)
assert.Equal(t, "image-registry.openshift-image-registry.svc:5000", reg.Name())

img = &storage.ImageName{
Registry: "image-registry.openshift-image-registry.svc.local:5000",
Remote: "qa/nginx",
Tag: "nginx:1.18.0",
FullName: "image-registry.openshift-image-registry.svc.local:5000/qa/nginx:1.18.0",
}
reg, err = regStore.GetRegistryForImage(img)
require.NoError(t, err)
assert.Equal(t, "image-registry.openshift-image-registry.svc.local:5000", reg.Name())

img = &storage.ImageName{
Registry: "172.99.12.11:5000",
Remote: "qa/nginx",
Tag: "nginx:1.18.0",
FullName: "172.99.12.11:5000/qa/nginx:1.18.0",
}
reg, err = regStore.GetRegistryForImage(img)
require.NoError(t, err)
assert.Equal(t, "172.99.12.11:5000", reg.Name())
}