-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
sts_regional_endpoints_spec.rb
165 lines (146 loc) · 5.72 KB
/
sts_regional_endpoints_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require_relative '../../spec_helper'
module Aws
module STS
describe Client do
describe ':sts_regional_endpoints' do
let(:mock_config_file) {
File.expand_path(File.join(File.dirname(__FILE__),
'..', 'fixtures', 'credentials', 'mock_shared_config'))
}
it 'uses ENV before shared config' do
ENV['AWS_STS_REGIONAL_ENDPOINTS'] = 'regional'
config = SharedConfig.new(
config_path: mock_config_file,
config_enabled: true,
profile_name: "sts_legacy"
)
allow(Aws).to receive(:shared_config).and_return(config)
client = Client.new(
stub_responses: true,
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
end
it 'defaults to `legacy`' do
client = Client.new(
stub_responses: true,
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('legacy')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.amazonaws.com')
end
it 'can be set `regional` in the constructor' do
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.us-west-2.amazonaws.com')
end
it 'can be set fron ENV' do
ENV['AWS_STS_REGIONAL_ENDPOINTS'] = 'regional'
client = Client.new(
stub_responses: true,
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.us-west-2.amazonaws.com')
end
it 'has no effect on fips endpoint' do
client = Client.new(
stub_responses: true,
region: 'us-west-2-fips'
)
expect(client.config.sts_regional_endpoints).to eq('legacy')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts-fips.us-west-2.amazonaws.com')
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'us-west-2-fips'
)
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts-fips.us-west-2.amazonaws.com')
end
it 'has no effect on aws-global even when `regional`' do
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'aws-global'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.amazonaws.com')
end
it 'has no effect on current regionalized regions' do
client = Client.new(
stub_responses: true,
region: 'ap-east-1'
)
expect(client.config.sts_regional_endpoints).to eq('legacy')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.ap-east-1.amazonaws.com')
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'ap-east-1'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.ap-east-1.amazonaws.com')
end
it 'has no effect on cn-north-1 region' do
client = Client.new(
stub_responses: true,
region: 'cn-north-1'
)
expect(client.config.sts_regional_endpoints).to eq('legacy')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.cn-north-1.amazonaws.com.cn')
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'cn-north-1'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
resp = client.get_caller_identity
expect(resp.context.http_request.endpoint.to_s).to eq(
'https://sts.cn-north-1.amazonaws.com.cn')
end
it 'configures properly at config' do
client = Client.new(
stub_responses: true,
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('legacy')
expect(client.config.region).to eq('us-west-2')
expect(client.config.sigv4_region).to eq('us-east-1')
expect(client.config.endpoint.to_s).to eq('https://sts.amazonaws.com')
client = Client.new(
stub_responses: true,
sts_regional_endpoints: 'regional',
region: 'us-west-2'
)
expect(client.config.sts_regional_endpoints).to eq('regional')
expect(client.config.region).to eq('us-west-2')
expect(client.config.sigv4_region).to eq('us-west-2')
expect(client.config.endpoint.to_s).to eq(
'https://sts.us-west-2.amazonaws.com')
end
end
end
end
end