forked from Mirrors/oauth2
fix test merge issue
This commit is contained in:
parent
523ee10d3c
commit
c93cd478e5
|
@ -1235,104 +1235,9 @@ func TestAWSCredential_ShouldCallMetadataEndpointWhenNoSecretAccessKey(t *testin
|
|||
}
|
||||
}
|
||||
|
||||
func TestAWSCredential_Validations(t *testing.T) {
|
||||
var metadataServerValidityTests = []struct {
|
||||
name string
|
||||
credSource CredentialSource
|
||||
errText string
|
||||
}{
|
||||
{
|
||||
name: "No Metadata Server URLs",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "",
|
||||
URL: "",
|
||||
IMDSv2SessionTokenURL: "",
|
||||
},
|
||||
}, {
|
||||
name: "IPv4 Metadata Server URLs",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "http://169.254.169.254/latest/meta-data/placement/availability-zone",
|
||||
URL: "http://169.254.169.254/latest/meta-data/iam/security-credentials",
|
||||
IMDSv2SessionTokenURL: "http://169.254.169.254/latest/api/token",
|
||||
},
|
||||
}, {
|
||||
name: "IPv6 Metadata Server URLs",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "http://[fd00:ec2::254]/latest/meta-data/placement/availability-zone",
|
||||
URL: "http://[fd00:ec2::254]/latest/meta-data/iam/security-credentials",
|
||||
IMDSv2SessionTokenURL: "http://[fd00:ec2::254]/latest/api/token",
|
||||
},
|
||||
}, {
|
||||
name: "Faulty RegionURL",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "http://abc.com/latest/meta-data/placement/availability-zone",
|
||||
URL: "http://169.254.169.254/latest/meta-data/iam/security-credentials",
|
||||
IMDSv2SessionTokenURL: "http://169.254.169.254/latest/api/token",
|
||||
},
|
||||
errText: "oauth2/google: invalid hostname http://abc.com/latest/meta-data/placement/availability-zone for region_url",
|
||||
}, {
|
||||
name: "Faulty CredVerificationURL",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "http://169.254.169.254/latest/meta-data/placement/availability-zone",
|
||||
URL: "http://abc.com/latest/meta-data/iam/security-credentials",
|
||||
IMDSv2SessionTokenURL: "http://169.254.169.254/latest/api/token",
|
||||
},
|
||||
errText: "oauth2/google: invalid hostname http://abc.com/latest/meta-data/iam/security-credentials for url",
|
||||
}, {
|
||||
name: "Faulty IMDSv2SessionTokenURL",
|
||||
credSource: CredentialSource{
|
||||
EnvironmentID: "aws1",
|
||||
RegionURL: "http://169.254.169.254/latest/meta-data/placement/availability-zone",
|
||||
URL: "http://169.254.169.254/latest/meta-data/iam/security-credentials",
|
||||
IMDSv2SessionTokenURL: "http://abc.com/latest/api/token",
|
||||
},
|
||||
errText: "oauth2/google: invalid hostname http://abc.com/latest/api/token for imdsv2_session_token_url",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range metadataServerValidityTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tfc := testFileConfig
|
||||
tfc.CredentialSource = tt.credSource
|
||||
|
||||
oldGetenv := getenv
|
||||
defer func() { getenv = oldGetenv }()
|
||||
getenv = setEnvironment(map[string]string{})
|
||||
|
||||
_, err := tfc.parse(context.Background())
|
||||
if err != nil {
|
||||
if tt.errText == "" {
|
||||
t.Errorf("Didn't expect an error, but got %v", err)
|
||||
} else if tt.errText != err.Error() {
|
||||
t.Errorf("Expected %v, but got %v", tt.errText, err)
|
||||
}
|
||||
} else {
|
||||
if tt.errText != "" {
|
||||
t.Errorf("Expected error %v, but got none", tt.errText)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAwsCredential_CredentialSourceType(t *testing.T) {
|
||||
server := createDefaultAwsTestServer()
|
||||
ts := httptest.NewServer(server)
|
||||
tsURL, err := neturl.Parse(ts.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("couldn't parse httptest servername")
|
||||
}
|
||||
|
||||
oldValidHostnames := validHostnames
|
||||
defer func() {
|
||||
validHostnames = oldValidHostnames
|
||||
}()
|
||||
validHostnames = []string{tsURL.Hostname()}
|
||||
|
||||
tfc := testFileConfig
|
||||
tfc.CredentialSource = server.getCredentialSource(ts.URL)
|
||||
|
|
Loading…
Reference in New Issue