|
70 | 70 | } } |
71 | 71 | subject { described_class.new(logger, options) } |
72 | 72 | let(:uri) { ::LogStash::Util::SafeURI.new("http://localhost:9200") } |
73 | | - let(:sign_aws_request) { } |
74 | 73 |
|
75 | | - it "should validate AWS IAM credentials initialization" do |
76 | | - expect(subject.aws_iam_auth_initialization(options)).not_to be_nil |
77 | | - expect(subject.get_service_name).to eq("es") |
78 | | - end |
79 | | - |
80 | | - it "should validate AWS IAM service_name config" do |
81 | | - expect(subject.aws_iam_auth_initialization(options_svc)).not_to be_nil |
82 | | - expect(subject.get_service_name).to eq("svc_test") |
83 | | - end |
| 74 | + let(:expected_uri) { |
| 75 | + expected_uri = uri.clone |
| 76 | + expected_uri.path = "/" |
| 77 | + expected_uri |
| 78 | + } |
84 | 79 |
|
85 | | - it "should validate signing aws request" do |
| 80 | + let(:resp) { |
86 | 81 | resp = double("response") |
87 | 82 | allow(resp).to receive(:call) |
88 | 83 | allow(resp).to receive(:code).and_return(200) |
89 | | - allow(subject).to receive(:sign_aws_request).with(any_args).and_return(sign_aws_request) |
| 84 | + resp |
| 85 | + } |
90 | 86 |
|
91 | | - expected_uri = uri.clone |
92 | | - expected_uri.path = "/" |
| 87 | + context 'with a signer' do |
| 88 | + let(:sign_aws_request) { } |
93 | 89 |
|
94 | | - expect(subject.manticore).to receive(:get). |
95 | | - with(expected_uri.to_s, { |
96 | | - :headers => {"content-type"=> "application/json"} |
97 | | - } |
| 90 | + it "should validate AWS IAM credentials initialization" do |
| 91 | + expect(subject.aws_iam_auth_initialization(options)).not_to be_nil |
| 92 | + expect(subject.get_service_name).to eq("es") |
| 93 | + end |
| 94 | + |
| 95 | + it "should validate AWS IAM service_name config" do |
| 96 | + expect(subject.aws_iam_auth_initialization(options_svc)).not_to be_nil |
| 97 | + expect(subject.get_service_name).to eq("svc_test") |
| 98 | + end |
| 99 | + |
| 100 | + it "should validate signing aws request" do |
| 101 | + allow(subject).to receive(:sign_aws_request).with(any_args).and_return(sign_aws_request) |
| 102 | + |
| 103 | + expect(subject.manticore).to receive(:get). |
| 104 | + with(expected_uri.to_s, { |
| 105 | + :headers => {"content-type"=> "application/json"} |
| 106 | + } |
| 107 | + ).and_return resp |
| 108 | + |
| 109 | + expect(subject).to receive(:sign_aws_request) |
| 110 | + subject.perform_request(uri, :get, "/") |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context 'sign_aws_request' do |
| 115 | + it 'handles UTF-8' do |
| 116 | + encoded_body = body = "boîte de réception" |
| 117 | + expect_any_instance_of(Aws::Sigv4::Signer).to receive(:sign_request).with(hash_including({ |
| 118 | + body: body, |
| 119 | + })).and_return( |
| 120 | + double(headers: {}) |
| 121 | + ) |
| 122 | + expect(subject.manticore).to receive(:post). |
| 123 | + with(expected_uri.to_s, { |
| 124 | + :body => encoded_body, |
| 125 | + :headers => {"content-type"=> "application/json"} |
| 126 | + } |
98 | 127 | ).and_return resp |
| 128 | + subject.perform_request(uri, :post, "/", { body: encoded_body }) |
| 129 | + end |
99 | 130 |
|
100 | | - expect(subject).to receive(:sign_aws_request) |
101 | | - subject.perform_request(uri, :get, "/") |
| 131 | + it 'encodes body before signing to match manticore adapter encoding' do |
| 132 | + body = "boîte de réception" |
| 133 | + encoded_body = body.encode("ISO-8859-1") |
| 134 | + expect_any_instance_of(Aws::Sigv4::Signer).to receive(:sign_request).with(hash_including({ |
| 135 | + body: body, |
| 136 | + })).and_return( |
| 137 | + double(headers: {}) |
| 138 | + ) |
| 139 | + expect(subject.manticore).to receive(:post). |
| 140 | + with(expected_uri.to_s, { |
| 141 | + :body => encoded_body, |
| 142 | + :headers => {"content-type"=> "application/json"} |
| 143 | + } |
| 144 | + ).and_return resp |
| 145 | + subject.perform_request(uri, :post, "/", { body: encoded_body }) |
| 146 | + end |
102 | 147 | end |
103 | 148 | end |
104 | 149 |
|
|
0 commit comments