Skip to content

Commit

Permalink
fix(archive): validate pro value when opening archive
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornplusplus committed Oct 17, 2024
1 parent 334d55a commit 2608ee3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var proArchiveInfo = map[string]struct {
}

// archiveURL returns the archive base URL depending on the "pro" value and
// selected architecture "arch". The "pro" value must be pre-validated.
// selected architecture "arch".
func archiveURL(pro, arch string) string {
if pro != "" {
return proArchiveInfo[pro].BaseURL
Expand All @@ -194,6 +194,11 @@ func openUbuntu(options *Options) (Archive, error) {
if len(options.Version) == 0 {
return nil, fmt.Errorf("archive options missing version")
}
if options.Pro != "" {
if _, ok := proArchiveInfo[options.Pro]; !ok {
return nil, fmt.Errorf("invalid pro value: %q", options.Pro)
}
}

baseURL := archiveURL(options.Pro, options.Arch)
var creds *credentials
Expand Down
10 changes: 10 additions & 0 deletions internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ var optionErrorTests = []optionErrorTest{{
Components: []string{"main", "other"},
},
error: `invalid package architecture: foo`,
}, {
options: archive.Options{
Label: "ubuntu",
Version: "22.04",
Arch: "amd64",
Suites: []string{"jammy"},
Components: []string{"main", "other"},
Pro: "invalid",
},
error: `invalid pro value: "invalid"`,
}}

func (s *httpSuite) TestOptionErrors(c *C) {
Expand Down

0 comments on commit 2608ee3

Please sign in to comment.