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