Skip to content

Commit

Permalink
Merge pull request #787 from hashicorp/more-config-file-parsing-tests
Browse files Browse the repository at this point in the history
Roll back INI parsing for trailing `#` error
  • Loading branch information
gdavison authored Nov 16, 2023
2 parents 83f96b8 + d442a7e commit ac073f9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
8 changes: 8 additions & 0 deletions aws_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,10 @@ func (d testCaseDriver) Apply(ctx context.Context, t *testing.T) (context.Contex
t.Errorf("unexpected diagnostics difference: %s", diff)
}

if diags.HasError() {
t.FailNow()
}

return ctx, thing(awsConfig)
}

Expand Down Expand Up @@ -3170,6 +3174,10 @@ func (t thing) GetRegion() string {
return t.Region
}

func (t thing) GetAwsConfig() aws.Config {
return aws.Config(t)
}

func TestSSO(t *testing.T) {
configtesting.SSO(t, &testDriver{})
}
Expand Down
16 changes: 14 additions & 2 deletions configtesting/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Thing interface {
GetRegion() string
}

type AwsConfigThing interface {
GetAwsConfig() aws.Config
}

type ConfigFunc func(c Configurer)

func WithProfile(s string) ConfigFunc {
Expand Down Expand Up @@ -161,7 +165,11 @@ sso_registration_scopes = sso:account:access

ctx, thing := caseDriver.Apply(ctx, t)

credentialsValue, err := thing.GetCredentials().Retrieve(ctx)
credentials := thing.GetCredentials()
if credentials == nil {
t.Fatal("credentials are nil")
}
credentialsValue, err := credentials.Retrieve(ctx)

if err != nil {
t.Fatalf("retrieving credentials: %s", err)
Expand Down Expand Up @@ -264,7 +272,11 @@ region = us-east-1

ctx, thing := caseDriver.Apply(ctx, t)

credentialsValue, err := thing.GetCredentials().Retrieve(ctx)
credentials := thing.GetCredentials()
if credentials == nil {
t.Fatal("credentials are nil")
}
credentialsValue, err := credentials.Retrieve(ctx)

if err != nil {
t.Fatalf("retrieving credentials: %s", err)
Expand Down
29 changes: 29 additions & 0 deletions configtesting/file_parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"testing"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/hashicorp/aws-sdk-go-base/v2/servicemocks"
)

Expand Down Expand Up @@ -35,6 +36,7 @@ region = us-west-2
}
},
},

"leading whitespace": {
// Do not "fix" indentation!
SharedConfigurationFile: ` [default]
Expand All @@ -47,6 +49,7 @@ region = us-west-2
}
},
},

"leading newline and whitespace": {
// Do not "fix" indentation!
SharedConfigurationFile: `
Expand All @@ -60,6 +63,7 @@ region = us-west-2
}
},
},

"named profile after leading newline and whitespace": {
Configuration: []ConfigFunc{
WithProfile("test"),
Expand All @@ -79,6 +83,7 @@ region = us-west-2
}
},
},

"named profile": {
Configuration: []ConfigFunc{
WithProfile("test"),
Expand All @@ -97,6 +102,30 @@ region = us-east-1
}
},
},

"trailing hash": {
SharedConfigurationFile: `
[default]
sso_start_url = https://d-123456789a.awsapps.com/start#
`,
Check: func(t *testing.T, thing Thing) {
ct, ok := thing.(AwsConfigThing)
if !ok {
t.Skipf("Not an AwsConfigThing")
}

awsConfig := ct.GetAwsConfig()
var ssoStartUrl string
for _, source := range awsConfig.ConfigSources {
if shared, ok := source.(config.SharedConfig); ok {
ssoStartUrl = shared.SSOStartURL
}
}
if a, e := ssoStartUrl, "https://d-123456789a.awsapps.com/start#"; a != e {
t.Errorf("expected sso_start_url %q, got %q", e, a)
}
},
},
}

for name, tc := range testcases {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/config v1.25.0
github.com/aws/aws-sdk-go-v2/config v1.20.0
github.com/aws/aws-sdk-go-v2/credentials v1.16.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.1
Expand All @@ -30,7 +30,7 @@ require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.2 // indirect
Expand All @@ -55,5 +55,7 @@ require (
exclude ( // Contains INI parsing regression
github.com/aws/aws-sdk-go-v2/config v1.21.0
github.com/aws/aws-sdk-go-v2/config v1.22.0
github.com/aws/aws-sdk-go-v2/config v1.25.0
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/aws/aws-sdk-go-v2 v1.22.2 h1:lV0U8fnhAnPz8YcdmZVV60+tr6CakHzqA6P8T46E
github.com/aws/aws-sdk-go-v2 v1.22.2/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ=
github.com/aws/aws-sdk-go-v2/config v1.25.0 h1:WCwAqyrM/kqYi6pHjVpq/w2pLydeGKv8Af9vdtO3ciM=
github.com/aws/aws-sdk-go-v2/config v1.25.0/go.mod h1:1QMnmhoWcR6957nC1MUUhhOLx9NOGFSVNG3Mag9vLU4=
github.com/aws/aws-sdk-go-v2/config v1.20.0 h1:q2+/mqFhY0J9m3Tb5RGFE3R4sdaUkIe4k2EuDfE3c08=
github.com/aws/aws-sdk-go-v2/config v1.20.0/go.mod h1:7+1riCZXyT+sAGvneR5j+Zl1GyfbBUNQurpQTE6FP6k=
github.com/aws/aws-sdk-go-v2/credentials v1.16.0 h1:sSEHkXonpZBSPcyUBDRlZjxOi14qM/UK7/vfKhGwmTo=
github.com/aws/aws-sdk-go-v2/credentials v1.16.0/go.mod h1:tXM8wmaeAhfC7nZoCxb0FzM/aRaB1m1WQ7x0qlBLq80=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 h1:G5KawTAkyHH6WyKQCdHiW4h3PmAXNJpOgwKg3H7sDRE=
Expand All @@ -12,8 +12,8 @@ github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 h1:AaQsr5vvGR7rmeSWBt
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2/go.mod h1:o1IiRn7CWocIFTXJjGKJDOwxv1ibL53NpcvcqGWyRBA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 h1:UZx8SXZ0YtzRiALzYAWcjb9Y9hZUR7MBKaBQ5ouOjPs=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2/go.mod h1:ipuRpcSaklmxR6C39G187TpBAO132gUfleTGccUPs8c=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0 h1:usgqiJtamuGIBj+OvYmMq89+Z1hIKkMJToz1WpoeNUY=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 h1:21tlTXq3ev10yLMAjXZzpkZbrl49h3ElSjmxD57tD/E=
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0/go.mod h1:d9YrBHJhyzDCv5UsEVRizHlFV6Q0sLemFq6uxuqWfUw=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2 h1:pyVrNAf7Hwz0u39dLKN5t+n0+K/3rMYKuiOoIum3AsU=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2/go.mod h1:mydrfOb9uiOYCxuCPR8YHQNQyGQwUQ7gPMZGBKbH8NY=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.1 h1:bqSGIS7Nk5EfMKTNDgtaukJQzjOE3LV5Bdz6lRrTsXA=
Expand Down
4 changes: 2 additions & 2 deletions v2/awsv1shim/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/aws/aws-sdk-go v1.47.11
github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/config v1.25.0
github.com/aws/aws-sdk-go-v2/config v1.20.0
github.com/aws/aws-sdk-go-v2/credentials v1.16.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1
Expand All @@ -21,7 +21,7 @@ require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.1 // indirect
github.com/aws/aws-sdk-go-v2/service/iam v1.27.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions v2/awsv1shim/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/aws/aws-sdk-go-v2 v1.22.2 h1:lV0U8fnhAnPz8YcdmZVV60+tr6CakHzqA6P8T46E
github.com/aws/aws-sdk-go-v2 v1.22.2/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ=
github.com/aws/aws-sdk-go-v2/config v1.25.0 h1:WCwAqyrM/kqYi6pHjVpq/w2pLydeGKv8Af9vdtO3ciM=
github.com/aws/aws-sdk-go-v2/config v1.25.0/go.mod h1:1QMnmhoWcR6957nC1MUUhhOLx9NOGFSVNG3Mag9vLU4=
github.com/aws/aws-sdk-go-v2/config v1.20.0 h1:q2+/mqFhY0J9m3Tb5RGFE3R4sdaUkIe4k2EuDfE3c08=
github.com/aws/aws-sdk-go-v2/config v1.20.0/go.mod h1:7+1riCZXyT+sAGvneR5j+Zl1GyfbBUNQurpQTE6FP6k=
github.com/aws/aws-sdk-go-v2/credentials v1.16.0 h1:sSEHkXonpZBSPcyUBDRlZjxOi14qM/UK7/vfKhGwmTo=
github.com/aws/aws-sdk-go-v2/credentials v1.16.0/go.mod h1:tXM8wmaeAhfC7nZoCxb0FzM/aRaB1m1WQ7x0qlBLq80=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 h1:G5KawTAkyHH6WyKQCdHiW4h3PmAXNJpOgwKg3H7sDRE=
Expand All @@ -14,8 +14,8 @@ github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 h1:AaQsr5vvGR7rmeSWBt
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2/go.mod h1:o1IiRn7CWocIFTXJjGKJDOwxv1ibL53NpcvcqGWyRBA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 h1:UZx8SXZ0YtzRiALzYAWcjb9Y9hZUR7MBKaBQ5ouOjPs=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2/go.mod h1:ipuRpcSaklmxR6C39G187TpBAO132gUfleTGccUPs8c=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0 h1:usgqiJtamuGIBj+OvYmMq89+Z1hIKkMJToz1WpoeNUY=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.0/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 h1:21tlTXq3ev10yLMAjXZzpkZbrl49h3ElSjmxD57tD/E=
github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0/go.mod h1:d9YrBHJhyzDCv5UsEVRizHlFV6Q0sLemFq6uxuqWfUw=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2 h1:pyVrNAf7Hwz0u39dLKN5t+n0+K/3rMYKuiOoIum3AsU=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2/go.mod h1:mydrfOb9uiOYCxuCPR8YHQNQyGQwUQ7gPMZGBKbH8NY=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.1 h1:bqSGIS7Nk5EfMKTNDgtaukJQzjOE3LV5Bdz6lRrTsXA=
Expand Down

0 comments on commit ac073f9

Please sign in to comment.