Skip to content

Commit 328d851

Browse files
committed
Add integration tests
Signed-off-by: Taras <9948629+taraspos@users.noreply.github.com>
1 parent dfe9588 commit 328d851

11 files changed

Lines changed: 97 additions & 12 deletions

File tree

tests/integration/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Using scratch base image results in `x509: certificate signed by unknown
22
# authority` error.
33
# Use alpine to include the necessary certificates.
4-
FROM alpine:3.16
4+
FROM alpine:3.23
55

66
COPY app .
77

tests/integration/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ test:
2121
test-aws:
2222
$(MAKE) test PROVIDER_ARG="-provider aws"
2323

24+
test-aws-git:
25+
$(MAKE) test PROVIDER_ARG="-provider aws" GO_TEST_PREFIX="TestGit"
26+
2427
test-azure:
2528
$(MAKE) test PROVIDER_ARG="-provider azure"
2629

tests/integration/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ metadata:
4949
### Amazon Web Services
5050

5151
- AWS account with access key ID and secret access key with permissions to
52-
create EKS cluster and ECR repository.
52+
create EKS cluster, ECR and a CodeCommit repositories.
5353
- AWS CLI v2.x, does not need to be configured with the AWS account.
5454
- Docker CLI for registry login.
5555
- kubectl for applying certain install manifests.
@@ -68,6 +68,13 @@ provisioning the infrastructure and running the tests:
6868
"Sid": "testinfra",
6969
"Effect": "Allow",
7070
"Action": [
71+
"codecommit:CreateRepository",
72+
"codecommit:DeleteRepository",
73+
"codecommit:GetRepository",
74+
"codecommit:TagResource",
75+
"codecommit:UntagResource",
76+
"codecommit:GitPull",
77+
"codecommit:GitPush",
7178
"ec2:AllocateAddress",
7279
"ec2:AssociateRouteTable",
7380
"ec2:AttachInternetGateway",
@@ -213,6 +220,13 @@ module "aws_gh_actions" {
213220
aws_policy_name = "oci-e2e"
214221
aws_policy_description = "policy for OCI e2e tests"
215222
aws_provision_perms = [
223+
"codecommit:CreateRepository",
224+
"codecommit:DeleteRepository",
225+
"codecommit:GetRepository",
226+
"codecommit:TagResource",
227+
"codecommit:UntagResource",
228+
"codecommit:GitPull",
229+
"codecommit:GitPush",
216230
"ec2:AllocateAddress",
217231
"ec2:AssociateRouteTable",
218232
"ec2:AttachInternetGateway",

tests/integration/aws_test.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ package integration
2222
import (
2323
"context"
2424
"fmt"
25+
"net/url"
2526

2627
tfjson "github.com/hashicorp/terraform-json"
2728

2829
"github.com/fluxcd/pkg/apis/meta"
30+
"github.com/fluxcd/pkg/auth"
2931
"github.com/fluxcd/pkg/auth/aws"
32+
authutils "github.com/fluxcd/pkg/auth/utils"
33+
"github.com/fluxcd/pkg/git"
3034
"github.com/fluxcd/test-infra/tftestenv"
3135
)
3236

@@ -94,7 +98,7 @@ func registryLoginECR(ctx context.Context, output map[string]*tfjson.StateOutput
9498
// logged in and is capable of pushing the test images.
9599
func pushAppTestImagesECR(ctx context.Context, localImgs map[string]string, output map[string]*tfjson.StateOutput) (map[string]string, error) {
96100
// Get the registry name and construct the image names accordingly.
97-
repo := output["ecr_test_app_repo_url"].Value.(string)
101+
repo := output["ecr_repository_url"].Value.(string)
98102
remoteImage := repo + ":test"
99103
return tftestenv.PushTestAppImagesECR(ctx, localImgs, remoteImage)
100104
}
@@ -138,17 +142,52 @@ func getClusterUsersAWS(output map[string]*tfjson.StateOutput) ([]string, error)
138142
return []string{clusterUser}, nil
139143
}
140144

141-
// When implemented, getGitTestConfigAws would return the git-specific test config for AWS
142145
func getGitTestConfigAWS(outputs map[string]*tfjson.StateOutput) (*gitTestConfig, error) {
143-
return nil, fmt.Errorf("NotImplemented for AWS")
146+
repoURL := outputs["git_repo_http_url"].Value.(string)
147+
if repoURL == "" {
148+
return nil, fmt.Errorf("no AWS CodeCommit repository URL in terraform output")
149+
}
150+
151+
region := outputs["region"].Value.(string)
152+
if region == "" {
153+
return nil, fmt.Errorf("no AWS region in terraform output")
154+
}
155+
156+
parsedRepoURL, err := url.Parse(repoURL)
157+
if err != nil {
158+
return nil, fmt.Errorf("failed to parse AWS CodeCommit repository URL: %w", err)
159+
}
160+
161+
creds, err := authutils.GetGitCredentials(context.Background(), aws.ProviderName,
162+
auth.WithSTSRegion(region),
163+
auth.WithGitURL(*parsedRepoURL),
164+
)
165+
if err != nil {
166+
return nil, fmt.Errorf("failed to get AWS CodeCommit credentials: %w", err)
167+
}
168+
169+
authOpts, err := getAuthOpts(repoURL, map[string][]byte{
170+
"username": []byte(creds.Username),
171+
"password": []byte(creds.Password),
172+
})
173+
if err != nil {
174+
return nil, err
175+
}
176+
177+
return &gitTestConfig{
178+
defaultGitTransport: git.HTTPS,
179+
defaultAuthOpts: authOpts,
180+
applicationRepository: repoURL,
181+
applicationRepositoryWithoutUser: repoURL,
182+
}, nil
144183
}
145184

146-
// When implemented, grantPermissionsToGitRepositoryAWS would grant the required permissions to AWS CodeCommit repository
147185
func grantPermissionsToGitRepositoryAWS(ctx context.Context, cfg *gitTestConfig, output map[string]*tfjson.StateOutput) error {
148-
return fmt.Errorf("NotImplemented for AWS")
186+
// Noop, CodeCommit permissions are granted via Terraform
187+
return nil
149188
}
150189

151-
// When implemented, revokePermissionsToGitRepositoryAWS would revoke the permissions granted to AWS CodeCommit repository
152190
func revokePermissionsToGitRepositoryAWS(ctx context.Context, cfg *gitTestConfig, outputs map[string]*tfjson.StateOutput) error {
153-
return fmt.Errorf("NotImplemented for AWS")
191+
// Noop, CodeCommit permissions are granted via Terraform
192+
return nil
154193
}

tests/integration/git_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ func TestGitCloneUsingProvider(t *testing.T) {
8383
}
8484

8585
func TestGitCloneUsingSSH(t *testing.T) {
86-
if !testGit {
86+
// Skip SSH authentication test for CodeCommit
87+
// while it is possible, it is based on SSH keys attached to an IAM user
88+
// which is not the recommended way.
89+
if *targetProvider == "aws" || !testGit {
8790
t.Skip("Skipping git test, not supported for provider")
8891
}
8992

tests/integration/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ require (
6969
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13 // indirect
7070
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect
7171
github.com/aws/smithy-go v1.24.0 // indirect
72+
github.com/aws/smithy-go/aws-http-auth v1.1.2-0.20260302195807-5bb6ea94670a // indirect
7273
github.com/beorn7/perks v1.0.1 // indirect
7374
github.com/blang/semver/v4 v4.0.0 // indirect
7475
github.com/cespare/xxhash/v2 v2.3.0 // indirect

tests/integration/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 h1:5fFjR/ToSOzB2OQ/XqWpZBmNvmP/
7373
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6/go.mod h1:qgFDZQSD/Kys7nJnVqYlWKnh0SSdMjAi0uSwON4wgYQ=
7474
github.com/aws/smithy-go v1.24.0 h1:LpilSUItNPFr1eY85RYgTIg5eIEPtvFbskaFcmmIUnk=
7575
github.com/aws/smithy-go v1.24.0/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
76+
github.com/aws/smithy-go/aws-http-auth v1.1.2-0.20260302195807-5bb6ea94670a h1:sN7kaGyTnpaIf0Ta59oeMjH59BYbyI+GvAs0wJgbLus=
77+
github.com/aws/smithy-go/aws-http-auth v1.1.2-0.20260302195807-5bb6ea94670a/go.mod h1:KL46VTjVK9De3jurMqDLBkXCP9vrAvD03zQrmyzyrQ0=
7678
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
7779
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
7880
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=

tests/integration/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func getProviderConfig(provider string) *ProviderConfig {
432432
grantPermissionsToGitRepository: grantPermissionsToGitRepositoryAWS,
433433
revokePermissionsToGitRepository: revokePermissionsToGitRepositoryAWS,
434434
getGitTestConfig: getGitTestConfigAWS,
435+
supportsGit: true,
435436
}
436437
case "azure":
437438
providerCfg := &ProviderConfig{

tests/integration/terraform/aws/main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ resource "aws_iam_role" "assume_role" {
5050
count = var.enable_wi ? 1 : 0
5151
name = local.name
5252
description = "IAM role used for testing Workload integration for OCI repositories in Flux"
53-
assume_role_policy = templatefile("oidc_assume_role_policy.json", {
53+
assume_role_policy = templatefile("${path.module}/oidc_assume_role_policy.json", {
5454
OIDC_ARN = module.eks.cluster_oidc_arn,
5555
OIDC_URL = replace(module.eks.cluster_oidc_url, "https://", ""),
5656
NAMESPACE = var.wi_k8s_sa_ns,
@@ -90,6 +90,14 @@ resource "aws_iam_policy" "wi_role_policy" {
9090
]
9191
Resource = "*"
9292
},
93+
{
94+
Effect = "Allow"
95+
Action = [
96+
"codecommit:GitPull",
97+
"codecommit:GitPush",
98+
]
99+
Resource = aws_codecommit_repository.test_git.arn
100+
},
93101
],
94102
})
95103
}
@@ -103,3 +111,9 @@ resource "aws_eks_access_entry" "wi_access_entry" {
103111
principal_arn = aws_iam_role.assume_role[0].arn
104112
user_name = aws_iam_role.assume_role[0].arn
105113
}
114+
115+
resource "aws_codecommit_repository" "test_git" {
116+
repository_name = local.name
117+
description = "Test repository for Flux integration tests"
118+
tags = var.tags
119+
}

tests/integration/terraform/aws/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ output "aws_wi_iam_arn" {
4747
output "ecrpublic_repository_url" {
4848
value = aws_ecrpublic_repository.test_ecr_public.repository_uri
4949
}
50+
51+
output "git_repo_http_url" {
52+
value = aws_codecommit_repository.test_git.clone_url_http
53+
}
54+
55+
output "git_repo_name" {
56+
value = aws_codecommit_repository.test_git.repository_name
57+
}

0 commit comments

Comments
 (0)