diff --git a/tariff/octopus.go b/tariff/octopus.go index 0958ca460..46cf4d5fc 100644 --- a/tariff/octopus.go +++ b/tariff/octopus.go @@ -97,8 +97,9 @@ func buildOctopusFromConfig(other map[string]any) (*Octopus, error) { if cc.Region != "" || cc.Tariff != "" { 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 - if cc.ApiKey != "test" && (len(cc.ApiKey) != 32 || !strings.HasPrefix(cc.ApiKey, "sk_live_")) { + // We permit the special "oe_test_" key prefix as sk_live_ keys are considered Stripe secrets by GitHub + // 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") } } diff --git a/tariff/octopus_test.go b/tariff/octopus_test.go index 272f278a9..15f46e99f 100644 --- a/tariff/octopus_test.go +++ b/tariff/octopus_test.go @@ -10,6 +10,9 @@ import ( func TestOctopusConfigParse(t *testing.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. validTariffConfig := map[string]any{ "region": "H", @@ -40,15 +43,22 @@ func TestOctopusConfigParse(t *testing.T) { invalidTariffDirectionConfig := map[string]any{ "tariffDirection": "invalid", - "apikey": "test", + "apikey": validTestApiKey32, } _, err = buildOctopusFromConfig(invalidTariffDirectionConfig) require.Errorf(t, err, "invalid tariff type") - validApiExportConfig := map[string]any{ + validApiExportConfig32 := map[string]any{ "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) }