1 | var assert = require('assert')
|
2 | var oauth = require('../index.js')
|
3 | var config = {
|
4 | "verify_api_key_url":"https://sfeldmanmicro-test.apigee.net/edgemicro-auth/verifyApiKey",
|
5 | "product_to_proxy":{"EdgeMicroTestProduct":["edgemicro_weather"]},
|
6 | "product_to_api_resource":{"EdgeMicroTestProduct":["/hello/blah/*/foo*","/hello/some/**","/hello/blah"]}
|
7 | };
|
8 | var config2 = {
|
9 | "verify_api_key_url":"https://sfeldmanmicro-test.apigee.net/edgemicro-auth/verifyApiKey",
|
10 | "product_to_proxy":{"EdgeMicroTestProduct":["edgemicro_weather"]},
|
11 | "product_to_api_resource":{"EdgeMicroTestProduct":[]}
|
12 | };
|
13 | var config3 = {
|
14 | "verify_api_key_url":"https://sfeldmanmicro-test.apigee.net/edgemicro-auth/verifyApiKey",
|
15 | "product_to_proxy":{"EdgeMicroTestProduct":["edgemicro_weather"]},
|
16 | "product_to_api_resource":{"EdgeMicroTestProduct":["/blah/*/foo*","/some/**","blah"]}
|
17 | };
|
18 |
|
19 | var proxy = {name:'edgemicro_weather',base_path:'/hello'}
|
20 |
|
21 | var token = {api_product_list:['EdgeMicroTestProduct']}
|
22 | describe('test oauth',function(){
|
23 | it('checkIfAuthorized',function (done) {
|
24 | var contains;
|
25 | contains = oauth.checkIfAuthorized(config,'/hello',proxy,token);
|
26 | assert(!contains)
|
27 | contains = oauth.checkIfAuthorized(config,'/hello/blah',proxy,token);
|
28 | assert(contains)
|
29 | contains = oauth.checkIfAuthorized(config,'/hello/blah/somerule/foosomething',proxy,token);
|
30 | assert(contains)
|
31 | contains = oauth.checkIfAuthorized(config,'/hello/blah/somerule/ifoosomething',proxy,token);
|
32 | assert(!contains)
|
33 | contains = oauth.checkIfAuthorized(config,'/hello/some/somerule/foosomething',proxy,token);
|
34 | assert(contains)
|
35 | done()
|
36 | })
|
37 | it('checkIfAuthorizedNoConfig',function (done) {
|
38 | var contains;
|
39 | contains = oauth.checkIfAuthorized(config2,'/hello',proxy,token);
|
40 | assert(contains)
|
41 | contains = oauth.checkIfAuthorized(config2,'/hello/blah',proxy,token);
|
42 | assert(contains)
|
43 | contains = oauth.checkIfAuthorized(config2,'/hello/blah/somerule/foosomething',proxy,token);
|
44 | assert(contains)
|
45 | contains = oauth.checkIfAuthorized(config2,'/hello/blah/somerule/ifoosomething',proxy,token);
|
46 | assert(contains)
|
47 | contains = oauth.checkIfAuthorized(config2,'/hello/some/somerule/foosomething',proxy,token);
|
48 | assert(contains)
|
49 | done()
|
50 | })
|
51 | it('checkIfAuthorized3',function (done) {
|
52 | var contains;
|
53 | contains = oauth.checkIfAuthorized(config3,'/hello',proxy,token);
|
54 | assert(!contains)
|
55 | contains = oauth.checkIfAuthorized(config3,'/hello/blah',proxy,token);
|
56 | assert(contains)
|
57 | contains = oauth.checkIfAuthorized(config3,'/hello/blah/somerule/foosomething',proxy,token);
|
58 | assert(contains)
|
59 | contains = oauth.checkIfAuthorized(config3,'/hello/blah/somerule/ifoosomething',proxy,token);
|
60 | assert(!contains)
|
61 | contains = oauth.checkIfAuthorized(config3,'/hello/some/somerule/foosomething',proxy,token);
|
62 | assert(contains)
|
63 | done()
|
64 | })
|
65 | })
|