Merge pull request #1387 from JasonYangShadow/issue/1371
Return an error indicating that name should not contain colon when importing containers
This commit is contained in:
@@ -40,6 +40,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Replace slice in templates with sprig substr. #1093
|
- Replace slice in templates with sprig substr. #1093
|
||||||
- Fix an invalid format issue for the GitHub nightly build action. #1258
|
- Fix an invalid format issue for the GitHub nightly build action. #1258
|
||||||
|
|
||||||
|
## v4.5.8, unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Return an error during `wwctl container import` if archive filename includes a colon. #1371
|
||||||
|
|
||||||
## v4.5.7, 2024-09-11
|
## v4.5.7, 2024-09-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ func getReference(uri string) (types.ImageReference, error) {
|
|||||||
case "docker-daemon":
|
case "docker-daemon":
|
||||||
return daemon.ParseReference(strings.TrimPrefix(s[1], "//"))
|
return daemon.ParseReference(strings.TrimPrefix(s[1], "//"))
|
||||||
case "file":
|
case "file":
|
||||||
return dockerarchive.ParseReference(strings.TrimPrefix(s[1], "/"))
|
reference := strings.TrimPrefix(s[1], "//")
|
||||||
|
if strings.Contains(reference, ":") {
|
||||||
|
return nil, fmt.Errorf("%s should not contain a colon", reference)
|
||||||
|
}
|
||||||
|
return dockerarchive.ParseReference(reference)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown uri scheme: %q", uri)
|
return nil, fmt.Errorf("unknown uri scheme: %q", uri)
|
||||||
}
|
}
|
||||||
|
|||||||
70
internal/pkg/oci/puller_test.go
Normal file
70
internal/pkg/oci/puller_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package oci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetReference(t *testing.T) {
|
||||||
|
temp, err := os.MkdirTemp(os.TempDir(), "ww-archive-*")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer os.RemoveAll(temp)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
uri string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "file archive ok case",
|
||||||
|
uri: "test.tar",
|
||||||
|
err: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "file archive ko case, because having colon in file name",
|
||||||
|
uri: "test:latest.tar",
|
||||||
|
err: fmt.Errorf("/test:latest.tar should not contain a colon"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "file archive ko case, because having colon in path name",
|
||||||
|
uri: "/test:/test.tar",
|
||||||
|
err: fmt.Errorf("/test:/test.tar should not contain a colon"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "docker ok case",
|
||||||
|
uri: "docker://test:latest",
|
||||||
|
err: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "docker daemon ok case",
|
||||||
|
uri: "docker-daemon://test:latest",
|
||||||
|
err: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Logf("running test: %s", tt.name)
|
||||||
|
if !strings.HasPrefix(tt.uri, "docker") && !strings.HasPrefix(tt.uri, "docker-daemon") {
|
||||||
|
tt.uri = filepath.Join(temp, tt.uri)
|
||||||
|
parent := filepath.Dir(tt.uri)
|
||||||
|
err := os.MkdirAll(parent, 0o755)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
f, err := os.Create(tt.uri)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, f.Close())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := getReference(tt.uri)
|
||||||
|
if tt.err == nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
} else {
|
||||||
|
assert.ErrorContains(t, err, tt.err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user