-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
describe('policy', function() | ||
describe('.rewrite', function() | ||
local test_service | ||
local context | ||
local soap_policy | ||
|
||
before_each(function() | ||
-- Called in the code, but in busted there is no request. Mocking. | ||
ngx.req.get_method = function() return 'GET' end | ||
|
||
-- Initialize a service that mocks get_usage() so we do not need to | ||
-- configure all the things we need to apply the real matching of | ||
-- mapping rules. | ||
-- We mock this get_usage() so it returns a different result depending | ||
-- on the SOAP action we pass so we can distinguish whether it comes | ||
-- from the SOAPAction header or the Content-Type one. | ||
test_service = { | ||
get_usage = function(_, method, soap_action_uri) | ||
if method == 'GET' and soap_action_uri == '/soap_action_ctype' then | ||
return { hits = 2 } | ||
elseif method == 'GET' and soap_action_uri == '/soap_action_header' then | ||
return { hits = 3 } | ||
else | ||
return {} | ||
end | ||
end | ||
} | ||
|
||
context = { service = test_service } | ||
|
||
soap_policy = require('apicast.policy.soap').new() | ||
end) | ||
|
||
describe('when the SOAP action is in the SOAPAction header', function() | ||
it('saves the metrics to increase in the context', function() | ||
ngx.req.get_headers = function() return { SOAPAction = '/soap_action_header' } end | ||
|
||
soap_policy:rewrite(context) | ||
|
||
assert.same({ hits = 3 }, context.add_to_usage) | ||
end) | ||
end) | ||
|
||
describe('when the SOAP action is in the Content-Type header', function() | ||
it('saves the metrics to increase in the context', function() | ||
ngx.req.get_headers = function() | ||
return { ["Content-Type"] = "application/soap+xml?action=/soap_action_ctype" } | ||
end | ||
|
||
soap_policy:rewrite(context) | ||
|
||
assert.same({ hits = 2 }, context.add_to_usage) | ||
end) | ||
end) | ||
|
||
describe('when the SOAP action is in the SOAPAction and the Content-Type headers', function() | ||
it('saves the metrics to increase in the context, ctype takes precedence', function() | ||
ngx.req.get_headers = function() | ||
return { | ||
SOAPAction = '/soap_action_header', | ||
["Content-Type"] = "application/soap+xml?action=/soap_action_ctype" | ||
} | ||
end | ||
|
||
soap_policy:rewrite(context) | ||
|
||
assert.same({ hits = 2 }, context.add_to_usage) | ||
end) | ||
end) | ||
|
||
describe('when the SOAP action is not specified', function() | ||
it('does not save anything in the context', function() | ||
ngx.req.get_headers = function() return {} end | ||
|
||
soap_policy:rewrite(context) | ||
|
||
assert.is_nil(context.add_to_usage) | ||
end) | ||
end) | ||
end) | ||
end) |