Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalizd image tag correction #138

Merged
merged 2 commits into from
Aug 14, 2023
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
13 changes: 7 additions & 6 deletions controllers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ func (h HTTPController) ScanRegistry(c *gin.Context) {

func registryScanCommandToScanCommand(c wssc.RegistryScanCommand) domain.ScanCommand {
command := domain.ScanCommand{
Credentialslist: c.Credentialslist,
ImageTag: c.ImageTag,
JobID: c.JobID,
ParentJobID: c.ParentJobID,
Args: c.Args,
Session: sessionChainToSession(c.Session),
Credentialslist: c.Credentialslist,
ImageTag: c.ImageTag,
ImageTagNormalized: tools.NormalizeReference(c.ImageTag),
JobID: c.JobID,
ParentJobID: c.ParentJobID,
Args: c.Args,
Session: sessionChainToSession(c.Session),
}
if slug, err := names.ImageInfoToSlug(c.ImageTag, "nohash"); err == nil {
command.ImageSlug = slug
Expand Down
68 changes: 68 additions & 0 deletions controllers/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"testing"

wssc "github.com/armosec/armoapi-go/apis"
"github.com/docker/docker/api/types"
"github.com/gammazero/workerpool"
"github.com/gin-gonic/gin"
"github.com/kubescape/kubevuln/core/ports"
Expand Down Expand Up @@ -210,3 +212,69 @@ func TestHTTPController_ScanRegistry(t *testing.T) {
})
}
}

func Test_registryScanCommandToScanCommand(t *testing.T) {

tests := []struct {
wssc.RegistryScanCommand
}{
{
wssc.RegistryScanCommand{
ImageScanParams: wssc.ImageScanParams{
Credentialslist: []types.AuthConfig{},
ImageTag: "docker.io/library/nginx:1.14.1",
JobID: "some Job ID for nginx",
ParentJobID: "some Parent Job ID for nginx",
},
},
},
{
wssc.RegistryScanCommand{
ImageScanParams: wssc.ImageScanParams{
Credentialslist: []types.AuthConfig{},
ImageTag: "nginx@sha256:73e957703f1266530db0aeac1fd6a3f87c1e59943f4c13eb340bb8521c6041d7",
JobID: "some Job ID for nginx sha",
ParentJobID: "some Parent Job ID for nginx sha",
},
},
},
{
wssc.RegistryScanCommand{
ImageScanParams: wssc.ImageScanParams{
Credentialslist: []types.AuthConfig{},
ImageTag: "nginx:latest",
JobID: "some Job ID for nginx latest",
ParentJobID: "some Parent Job ID for nginx latest",
},
},
},
{
wssc.RegistryScanCommand{
ImageScanParams: wssc.ImageScanParams{
Credentialslist: []types.AuthConfig{},
ImageTag: "docker.io/library/nginx:latest",
JobID: "some Job ID for nginx latest with docker hub",
ParentJobID: "some Parent Job ID for nginx latest with docker hub",
},
},
},
{
wssc.RegistryScanCommand{
ImageScanParams: wssc.ImageScanParams{
Credentialslist: []types.AuthConfig{},
ImageTag: "docker.io/library/nginx:latest@sha256:73e957703f1266530db0aeac1fd6a3f87c1e59943f4c13eb340bb8521c6041d7",
JobID: "some Job ID for nginx latest with docker hub library",
ParentJobID: "some Parent Job ID for nginx latest with docker hub library",
},
},
},
}
for i := range tests {
scanComm := registryScanCommandToScanCommand(tests[i].RegistryScanCommand)
assert.Equal(t, tests[i].Credentialslist, scanComm.Credentialslist)
assert.Equal(t, tests[i].ImageTag, scanComm.ImageTag)
assert.Equal(t, tools.NormalizeReference(tests[i].ImageTag), scanComm.ImageTagNormalized)
assert.Equal(t, tests[i].JobID, scanComm.JobID)
assert.Equal(t, tests[i].ParentJobID, scanComm.ParentJobID)
}
}
7 changes: 7 additions & 0 deletions internal/tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func TestNormalizeReference(t *testing.T) {
},
want: "quay.io/kubescape/kubevuln:latest@sha256:616d1d4312551b94088deb6ddab232ecabbbff0c289949a0d5f12d4b527c3f8a",
},
{
name: "some image other registry",
args: args{
ref: "public-registry.systest-ns-na6n:5000/nginx:test",
},
want: "public-registry.systest-ns-na6n:5000/nginx:test",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading