Skip to content

Commit

Permalink
Avoid leaking account id in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ugexe committed Jul 10, 2023
1 parent 08dce57 commit ad02665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/geoipupdate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func setConfigFromFile(config *Config, path string) error {
case "AccountID", "UserId":
accountID, err := strconv.Atoi(value)
if err != nil {
return fmt.Errorf("invalid account ID format: %w", err)
return fmt.Errorf("invalid account ID format")
}
config.AccountID = accountID
keysSeen["AccountID"] = struct{}{}
Expand Down Expand Up @@ -286,7 +286,7 @@ func setConfigFromEnv(config *Config) error {
var err error
config.AccountID, err = strconv.Atoi(value)
if err != nil {
return fmt.Errorf("invalid account ID format: %w", err)
return fmt.Errorf("invalid account ID format")
}
}

Expand All @@ -300,7 +300,7 @@ func setConfigFromEnv(config *Config) error {

config.AccountID, err = strconv.Atoi(string(accountID))
if err != nil {
return fmt.Errorf("invalid account ID format: %w", err)
return fmt.Errorf("invalid account ID format")
}
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/geoipupdate/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ UserId 456
Description: "Invalid account ID",
Input: `AccountID 1a
`,
Err: `invalid account ID format: strconv.Atoi: parsing "1a": invalid syntax`,
Err: `invalid account ID format`,
},
{
Description: "Invalid PreserveFileTimes",
Expand Down Expand Up @@ -394,8 +394,7 @@ SkipPeerVerification 1
{
Description: "CR line ending does not work",
Input: "AccountID 0\rLicenseKey 123\rEditionIDs GeoIP2-City\r",
//nolint: lll
Err: `invalid account ID format: strconv.Atoi: parsing "0 LicenseKey 123 EditionIDs GeoIP2-City": invalid syntax`,
Err: `invalid account ID format`,
},
{
Description: "Multiple spaces between option and value works",
Expand Down Expand Up @@ -527,7 +526,7 @@ func TestSetConfigFromFile(t *testing.T) {
{
Description: "Invalid account ID",
Input: "AccountID 1a",
Err: `invalid account ID format: strconv.Atoi: parsing "1a": invalid syntax`,
Err: `invalid account ID format`,
},
{
Description: "Invalid PreserveFileTimes",
Expand Down Expand Up @@ -661,7 +660,7 @@ func TestSetConfigFromEnv(t *testing.T) {
Env: map[string]string{
"GEOIPUPDATE_ACCOUNT_ID": "1a",
},
Err: `invalid account ID format: strconv.Atoi: parsing "1a": invalid syntax`,
Err: `invalid account ID format`,
},
{
Description: "Invalid PreserveFileTimes",
Expand Down

0 comments on commit ad02665

Please sign in to comment.