Octopus: Support new-format 40-character API keys (#26755)
This commit is contained in:
parent
4d5f374576
commit
f179391526
2 changed files with 17 additions and 6 deletions
|
|
@ -97,8 +97,9 @@ func buildOctopusFromConfig(other map[string]any) (*Octopus, error) {
|
||||||
if cc.Region != "" || cc.Tariff != "" {
|
if cc.Region != "" || cc.Tariff != "" {
|
||||||
return nil, errors.New("cannot use apikey at same time as product code")
|
return nil, errors.New("cannot use apikey at same time as product code")
|
||||||
}
|
}
|
||||||
// We permit the specific special apiKey "test" as sk_live_ keys are considered Stripe secrets by Github
|
// We permit the special "oe_test_" key prefix as sk_live_ keys are considered Stripe secrets by GitHub
|
||||||
if cc.ApiKey != "test" && (len(cc.ApiKey) != 32 || !strings.HasPrefix(cc.ApiKey, "sk_live_")) {
|
// Keys are either 32 or 40 characters long
|
||||||
|
if (len(cc.ApiKey) != 32 && len(cc.ApiKey) != 40) || (!strings.HasPrefix(cc.ApiKey, "sk_live_") && !strings.HasPrefix(cc.ApiKey, "oe_test_")) {
|
||||||
return nil, errors.New("invalid apikey format")
|
return nil, errors.New("invalid apikey format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@ import (
|
||||||
func TestOctopusConfigParse(t *testing.T) {
|
func TestOctopusConfigParse(t *testing.T) {
|
||||||
test.SkipCI(t)
|
test.SkipCI(t)
|
||||||
|
|
||||||
|
validTestApiKey32 := "oe_test_testingYqLeoRu2xsn9WEiv6"
|
||||||
|
validTestApiKey40 := "oe_test_testingYBsFMxfqXG9guAdTVgFssdJmv"
|
||||||
|
|
||||||
// This test will start failing if you remove the deprecated "tariff" config var.
|
// This test will start failing if you remove the deprecated "tariff" config var.
|
||||||
validTariffConfig := map[string]any{
|
validTariffConfig := map[string]any{
|
||||||
"region": "H",
|
"region": "H",
|
||||||
|
|
@ -40,15 +43,22 @@ func TestOctopusConfigParse(t *testing.T) {
|
||||||
|
|
||||||
invalidTariffDirectionConfig := map[string]any{
|
invalidTariffDirectionConfig := map[string]any{
|
||||||
"tariffDirection": "invalid",
|
"tariffDirection": "invalid",
|
||||||
"apikey": "test",
|
"apikey": validTestApiKey32,
|
||||||
}
|
}
|
||||||
_, err = buildOctopusFromConfig(invalidTariffDirectionConfig)
|
_, err = buildOctopusFromConfig(invalidTariffDirectionConfig)
|
||||||
require.Errorf(t, err, "invalid tariff type")
|
require.Errorf(t, err, "invalid tariff type")
|
||||||
|
|
||||||
validApiExportConfig := map[string]any{
|
validApiExportConfig32 := map[string]any{
|
||||||
"tariffDirection": "export",
|
"tariffDirection": "export",
|
||||||
"apikey": "test",
|
"apikey": validTestApiKey32,
|
||||||
}
|
}
|
||||||
_, err = buildOctopusFromConfig(validApiExportConfig)
|
_, err = buildOctopusFromConfig(validApiExportConfig32)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
validApiExportConfig40 := map[string]any{
|
||||||
|
"tariffDirection": "export",
|
||||||
|
"apikey": validTestApiKey40,
|
||||||
|
}
|
||||||
|
_, err = buildOctopusFromConfig(validApiExportConfig40)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue