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

fix(pkg/narinfo): Treat unknown-deriver as no deriver #128

Merged
merged 1 commit into from
Jan 1, 2025
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
41 changes: 41 additions & 0 deletions pkg/narinfo/narinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ References: 7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27
Deriver: 10dx1q4ivjb115y3h90mipaaz533nr0d-net-tools-1.60_p20170221182432.drv
Sig: cache.nixos.org-1:sn5s/RrqEI+YG6/PjwdbPjcAC7rcta7sJU4mFOawGvJBLsWkyLtBrT2EuFt/LJjWkTZ+ZWOI9NTtjo/woMdvAg==
Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7acJjLn3jofOtilAAwRILKIfVuyrbjAA==
`
strNarinfoSampleWithUnknownDeriver = `
StorePath: /nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432
URL: nar/1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d.nar.xz
Compression: xz
FileHash: sha256:1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d
FileSize: 114980
NarHash: sha256:0lxjvvpr59c2mdram7ympy5ay741f180kv3349hvfc3f8nrmbqf6
NarSize: 464152
References: 7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27
Deriver: unknown-deriver
Sig: cache.nixos.org-1:sn5s/RrqEI+YG6/PjwdbPjcAC7rcta7sJU4mFOawGvJBLsWkyLtBrT2EuFt/LJjWkTZ+ZWOI9NTtjo/woMdvAg==
Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7acJjLn3jofOtilAAwRILKIfVuyrbjAA==
`
strNarinfoSampleWithoutFileFields = `
StorePath: /nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432
Expand Down Expand Up @@ -139,6 +152,18 @@ Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7ac
Signatures: _SignaturesNarinfoSample,
}

narinfoSampleWithUnknownDeriver = &narinfo.NarInfo{
StorePath: "/nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432",
URL: "nar/1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d.nar.xz",
Compression: "xz",
FileHash: mustParseAny("sha256:1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d"),
FileSize: 114980,
NarHash: _NarHash,
NarSize: 464152,
References: []string{"7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27"},
Signatures: _SignaturesNarinfoSample,
}

narinfoSampleWithoutFileFields = &narinfo.NarInfo{
StorePath: "/nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432",
URL: "nar/1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d.nar.xz",
Expand Down Expand Up @@ -220,6 +245,22 @@ func TestNarInfoWithBase16Hash(t *testing.T) {
assert.Equal(t, strNarinfoSampleWithBase16Hash, "\n"+ni.String())
}

func TestNarInfoWithUnknownDeriver(t *testing.T) {
ni, err := narinfo.Parse(strings.NewReader(strNarinfoSampleWithUnknownDeriver))
assert.NoError(t, err)

// Test the parsing happy path
assert.Equal(t, narinfoSampleWithUnknownDeriver, ni)
assert.NoError(t, ni.Check())

// Test to string
assert.Equal(
t,
strings.Replace(strNarinfoSampleWithUnknownDeriver, "Deriver: unknown-deriver\n", "", -1),
"\n"+ni.String(),
)
}

func TestNarInfoUncompressed(t *testing.T) {
ni, err := narinfo.Parse(strings.NewReader(strNarinfoSampleUncompressed))
assert.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/narinfo/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func Parse(r io.Reader) (*NarInfo, error) {

narInfo.References = append(narInfo.References, strings.Split(v, " ")...)
case "Deriver":
narInfo.Deriver = v
if v != "unknown-deriver" {
narInfo.Deriver = v
}
case "System":
narInfo.System = v
case "Sig":
Expand Down
Loading