-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Mastercard/fixing-encoding
Fixing NodeJs OAuth signer to handle already encoded params
- Loading branch information
Showing
5 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -1,16 +1,37 @@ | ||
const assert = require("assert"); | ||
const OAuth = require("../src/OAuth"); | ||
const getSignatureBaseString = require("../src/OAuth").getSignatureBaseString; | ||
const toOauthParamString = require("../src/OAuth").toOAuthParamString; | ||
const extractQueryParams = require("../src/OAuth").extractQueryParams; | ||
|
||
describe("OAuth Signer", function() { | ||
describe("#getSignatureBaseString()", function() { | ||
it("Creates a correctly constructed and escaped signature base string", function() { | ||
const httpMethod = "GET"; | ||
const baseUri = "https://sandbox.api.mastercard.com/merchantid/v1/merchantid"; | ||
const paramString = "Format=JSON&Format=XML&MerchantId=GOOGLE%20LTD%20ADWORDS%20%28CC%40GOOGLE.COM%29&Type=ExactMatch&oauth_consumer_key=aaa!aaa&oauth_nonce=uTeLPs6K&oauth_signature_method=RSA-SHA256&oauth_timestamp=1524771555&oauth_version=1.0"; | ||
const paramString = "Format=JSON&Format=XML&MerchantId=GOOGLE%20LTD%20ADWORDS%20CC%40GOOGLE.COM&Type=ExactMatch&oauth_consumer_key=aaa!aaa&oauth_nonce=uTeLPs6K&oauth_signature_method=RSA-SHA256&oauth_timestamp=1524771555&oauth_version=1.0"; | ||
const sbs = getSignatureBaseString(httpMethod, baseUri, paramString); | ||
|
||
assert.deepEqual(sbs, "GET&https%3A%2F%2Fsandbox.api.mastercard.com%2Fmerchantid%2Fv1%2Fmerchantid&Format%3DJSON%26Format%3DXML%26MerchantId%3DGOOGLE%2520LTD%2520ADWORDS%2520%2528CC%2540GOOGLE.COM%2529%26Type%3DExactMatch%26oauth_consumer_key%3Daaa%21aaa%26oauth_nonce%3DuTeLPs6K%26oauth_signature_method%3DRSA-SHA256%26oauth_timestamp%3D1524771555%26oauth_version%3D1.0"); | ||
assert.deepEqual(sbs, "GET&https%3A%2F%2Fsandbox.api.mastercard.com%2Fmerchantid%2Fv1%2Fmerchantid&Format%3DJSON%26Format%3DXML%26MerchantId%3DGOOGLE%20LTD%20ADWORDS%20CC%40GOOGLE.COM%26Type%3DExactMatch%26oauth_consumer_key%3Daaa%21aaa%26oauth_nonce%3DuTeLPs6K%26oauth_signature_method%3DRSA-SHA256%26oauth_timestamp%3D1524771555%26oauth_version%3D1.0"); | ||
}); | ||
|
||
it("Should create expected base string when query params are encoded", function() { | ||
const encodedUri = "https://example.com/?param=token1%3Atoken2"; | ||
const encodedParams = extractQueryParams(encodedUri); | ||
const paramString = toOauthParamString(encodedParams, new Map()); | ||
const baseString = getSignatureBaseString("GET", "https://example.com", paramString); | ||
|
||
assert.deepEqual("GET&https%3A%2F%2Fexample.com¶m%3Dtoken1%3Atoken2", baseString); | ||
}); | ||
|
||
it("Should create expected base string when query params are not encoded", function() { | ||
|
||
const nonEncodedUri = "https://example.com/?param=token1:token2"; | ||
const nonEncodedParams = extractQueryParams(nonEncodedUri); | ||
const paramString = toOauthParamString(nonEncodedParams, new Map()); | ||
const baseString = getSignatureBaseString("GET", "https://example.com", paramString); | ||
|
||
assert.deepEqual("GET&https%3A%2F%2Fexample.com¶m%3Dtoken1%3Atoken2", baseString); | ||
}); | ||
}); | ||
}); |