Browse Source

test(e2e): skip sts generator v2 with session creds

Moritz Johner 2 months ago
parent
commit
1e946a37df
3 changed files with 42 additions and 0 deletions
  1. 4 0
      e2e/suites/generator/aws.go
  2. 35 0
      e2e/suites/generator/aws_test.go
  3. 3 0
      e2e/suites/generator/sts_v2.go

+ 4 - 0
e2e/suites/generator/aws.go

@@ -73,3 +73,7 @@ func awsGeneratorAuth() genv1alpha1.AWSAuth {
 	}
 	return auth
 }
+
+func awsSTSSessionTokenGeneratorSupported() bool {
+	return os.Getenv("AWS_SESSION_TOKEN") == ""
+}

+ 35 - 0
e2e/suites/generator/aws_test.go

@@ -0,0 +1,35 @@
+/*
+Copyright © The ESO Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    https://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package generator
+
+import "testing"
+
+func TestAWSSTSSessionTokenGeneratorSupported(t *testing.T) {
+	t.Setenv("AWS_SESSION_TOKEN", "")
+
+	if !awsSTSSessionTokenGeneratorSupported() {
+		t.Fatal("expected sts session token generator to support static credentials")
+	}
+}
+
+func TestAWSSTSSessionTokenGeneratorUnsupportedWithSessionCredentials(t *testing.T) {
+	t.Setenv("AWS_SESSION_TOKEN", "session-token")
+
+	if awsSTSSessionTokenGeneratorSupported() {
+		t.Fatal("expected sts session token generator to skip when session credentials are already in use")
+	}
+}

+ 3 - 0
e2e/suites/generator/sts_v2.go

@@ -37,6 +37,9 @@ var _ = Describe("sts generator v2", Label("aws", "sts", "v2"), func() {
 			Skip("v2 mode only")
 		}
 		skipIfAWSGeneratorCredentialsMissing()
+		if !awsSTSSessionTokenGeneratorSupported() {
+			Skip("AWS STS session token generator requires long-lived credentials and cannot be exercised with AWS_SESSION_TOKEN")
+		}
 	})
 
 	injectGenerator := func(tc *testCase) {