Skip to content

Commit 1a2e90b

Browse files
committed
test(s3-binary-cache-store): add profile support for setup_for_s3
1 parent 35f59f1 commit 1a2e90b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/nixos/s3-binary-cache-store.nix

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ in
147147
else:
148148
machine.fail(f"nix path-info {pkg}")
149149
150-
def setup_s3(populate_bucket=[], public=False, versioned=False):
150+
def setup_s3(populate_bucket=[], public=False, versioned=False, profiles=None):
151151
"""
152152
Decorator that creates/destroys a unique bucket for each test.
153153
Optionally pre-populates bucket with specified packages.
@@ -157,6 +157,10 @@ in
157157
populate_bucket: List of packages to upload before test runs
158158
public: If True, make the bucket publicly accessible
159159
versioned: If True, enable versioning on the bucket before populating
160+
profiles: Dict of AWS profiles to create, e.g.:
161+
{"valid": {"access_key": "...", "secret_key": "..."},
162+
"invalid": {"access_key": "WRONG", "secret_key": "WRONG"}}
163+
Profiles are created on the client machine at /root/.aws/credentials
160164
"""
161165
def decorator(test_func):
162166
def wrapper():
@@ -167,13 +171,25 @@ in
167171
server.succeed(f"mc anonymous set download minio/{bucket}")
168172
if versioned:
169173
server.succeed(f"mc version enable minio/{bucket}")
174+
if profiles:
175+
# Build credentials file content
176+
creds_content = ""
177+
for name, creds in profiles.items():
178+
creds_content += f"[{name}]\n"
179+
creds_content += f"aws_access_key_id = {creds['access_key']}\n"
180+
creds_content += f"aws_secret_access_key = {creds['secret_key']}\n\n"
181+
client.succeed("mkdir -p /root/.aws")
182+
client.succeed(f"cat > /root/.aws/credentials << 'AWSCREDS'\n{creds_content}AWSCREDS")
170183
if populate_bucket:
171184
store_url = make_s3_url(bucket)
172185
for pkg in populate_bucket:
173186
server.succeed(f"{ENV_WITH_CREDS} nix copy --to '{store_url}' {pkg}")
174187
test_func(bucket)
175188
finally:
176189
server.succeed(f"mc rb --force minio/{bucket}")
190+
# Clean up AWS profiles if created
191+
if profiles:
192+
client.succeed("rm -rf /root/.aws")
177193
# Clean up client store - only delete if path exists
178194
for pkg in PKGS.values():
179195
client.succeed(f"[ ! -e {pkg} ] || nix store delete --ignore-liveness {pkg}")

0 commit comments

Comments
 (0)