@@ -5,11 +5,13 @@ import (
55 "fmt"
66 "log"
77 "os"
8+ "regexp"
89 "strings"
910 "testing"
1011 "time"
1112
1213 "github.com/aws/aws-sdk-go-v2/aws"
14+ "github.com/aws/aws-sdk-go-v2/aws/arn"
1315 "github.com/aws/aws-sdk-go-v2/config"
1416 "github.com/cert-manager/aws-privateca-issuer/pkg/api/v1beta1"
1517 clientV1beta1 "github.com/cert-manager/aws-privateca-issuer/pkg/clientset/v1beta1"
@@ -31,7 +33,7 @@ type TestContext struct {
3133 xaCfg aws.Config
3234 caArns map [string ]string
3335
34- region , partition , accessKey , secretKey , endEntityResourceShareArn , subordinateCaResourceShareArn , userName , policyArn string
36+ region , partition , accessKey , secretKey , endEntityResourceShareArn , subordinateCaResourceShareArn , userName , policyArn , accountId , domain string
3537}
3638
3739// These are variables specific to each test
@@ -111,7 +113,23 @@ func InitializeTestSuite(suiteCtx *godog.TestSuiteContext) {
111113 panic (cfgErr .Error ())
112114 }
113115
114- testContext .partition = getPartition (ctx , cfg )
116+ callerID := getCallerIdentity (ctx , cfg )
117+ testContext .accountId = * callerID .Account
118+
119+ parsedArn , parseErr := arn .Parse (* callerID .Arn )
120+ if parseErr != nil {
121+ panic ("Failed to parse caller identity ARN: " + parseErr .Error ())
122+ }
123+
124+ testContext .partition = parsedArn .Partition
125+
126+ // Match the complete resource: assumed-role/RoleName-DOMAIN-region/i-xxxxxxxxx
127+ re := regexp .MustCompile (`^assumed-role/[^-]+-([^-]+)-[^/]+/i-[a-f0-9]+$` )
128+ matches := re .FindStringSubmatch (parsedArn .Resource )
129+ if len (matches ) < 2 {
130+ panic ("Failed to extract domain from caller identity resource: " + parsedArn .Resource )
131+ }
132+ testContext .domain = matches [1 ]
115133
116134 testContext .iclient , err = clientV1beta1 .NewForConfig (clientConfig )
117135
@@ -217,8 +235,10 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
217235 ctx .Step (`^I create a namespace` , issuerContext .createNamespace )
218236 ctx .Step (`^I create a Secret with keys ([A-Za-z_]+) and ([A-Za-z_]+) for my AWS credentials$` , issuerContext .createSecret )
219237 ctx .Step (`^I create an AWSPCAClusterIssuer using a (RSA|ECDSA|XA) CA$` , issuerContext .createClusterIssuer )
238+ ctx .Step (`^I create an AWSPCAClusterIssuer with role assumption$` , issuerContext .createClusterIssuerWithRole )
220239 ctx .Step (`^I delete the AWSPCAClusterIssuer$` , issuerContext .deleteClusterIssuer )
221240 ctx .Step (`^I create an AWSPCAIssuer using a (RSA|ECDSA|XA) CA$` , issuerContext .createNamespaceIssuer )
241+ ctx .Step (`^I create an AWSPCAIssuer with role assumption$` , issuerContext .createNamespaceIssuerWithRole )
222242 ctx .Step (`^I issue a (SHORT_VALIDITY|RSA|ECDSA|CA) certificate$` , issuerContext .issueCertificate )
223243 ctx .Step (`^the certificate should be issued successfully$` , issuerContext .verifyCertificateIssued )
224244 ctx .Step (`^the certificate request has been created$` , issuerContext .verifyCertificateRequestIsCreated )
0 commit comments