Skip to content

Commit 1564a9c

Browse files
committed
Stub calls to AWS metadata API on CI.
1 parent 9a7b985 commit 1564a9c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

spec/spec_helper.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,25 @@
2828
SSHKit::EC2InstanceConnect::Backend.ssh_keys.clear
2929
SSHKit::EC2InstanceConnect::Backend.tunnels.clear
3030
end
31+
32+
# Stub calls to AWS metadata API on CI.
33+
if ENV['CI']
34+
config.before do
35+
stub_request(:put, 'http://169.254.169.254/latest/api/token').to_return(status: 200)
36+
37+
stub_request(:get, 'http://169.254.169.254/latest/meta-data/iam/security-credentials/')
38+
.to_return(status: 200, body: 'DummyRole')
39+
40+
stub_request(:get, 'http://169.254.169.254/latest/meta-data/iam/security-credentials/DummyRole')
41+
.to_return(status: 200, body: {
42+
Code: 'Success',
43+
LastUpdated: Time.now.utc.iso8601,
44+
Type: 'AWS-HMAC',
45+
AccessKeyId: SecureRandom.alphanumeric(10),
46+
SecretAccessKey: SecureRandom.alphanumeric(20),
47+
Token: SecureRandom.alphanumeric(60),
48+
Expiration: (Time.now + 3600).utc.iso8601
49+
}.to_json)
50+
end
51+
end
3152
end

0 commit comments

Comments
 (0)