UNPKG

5.34 kBJavaScriptView Raw
1process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
2import oada from "../src/index";
3import chai from "chai";
4var expect = chai.expect;
5const status = require("http-status");
6//let domain = "https://vip3.ecn.purdue.edu";
7let domain = "https://localhost";
8let connectTime = 30 * 1000; // seconds to click through oauth
9let nTests = 5;
10const _ = require("lodash");
11let expiredConnections = new Array(10);
12
13let connectionParameters = {
14 domain,
15 options: {
16 redirect: "http://localhost:8000/oauth2/redirect.html",
17 metadata:
18 "eyJqa3UiOiJodHRwczovL2lkZW50aXR5Lm9hZGEtZGV2LmNvbS9jZXJ0cyIsImtpZCI6ImtqY1NjamMzMmR3SlhYTEpEczNyMTI0c2ExIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJyZWRpcmVjdF91cmlzIjpbImh0dHA6Ly92aXAzLmVjbi5wdXJkdWUuZWR1OjgwMDAvb2F1dGgyL3JlZGlyZWN0Lmh0bWwiLCJodHRwOi8vbG9jYWxob3N0OjgwMDAvb2F1dGgyL3JlZGlyZWN0Lmh0bWwiXSwidG9rZW5fZW5kcG9pbnRfYXV0aF9tZXRob2QiOiJ1cm46aWV0ZjpwYXJhbXM6b2F1dGg6Y2xpZW50LWFzc2VydGlvbi10eXBlOmp3dC1iZWFyZXIiLCJncmFudF90eXBlcyI6WyJpbXBsaWNpdCJdLCJyZXNwb25zZV90eXBlcyI6WyJ0b2tlbiIsImlkX3Rva2VuIiwiaWRfdG9rZW4gdG9rZW4iXSwiY2xpZW50X25hbWUiOiJPcGVuQVRLIiwiY2xpZW50X3VyaSI6Imh0dHBzOi8vdmlwMy5lY24ucHVyZHVlLmVkdSIsImNvbnRhY3RzIjpbIlNhbSBOb2VsIDxzYW5vZWxAcHVyZHVlLmVkdT4iXSwic29mdHdhcmVfaWQiOiIxZjc4NDc3Zi0zNTQxLTQxM2ItOTdiNi04NjQ0YjRhZjViYjgiLCJyZWdpc3RyYXRpb25fcHJvdmlkZXIiOiJodHRwczovL2lkZW50aXR5Lm9hZGEtZGV2LmNvbSIsImlhdCI6MTUxMjAwNjc2MX0.AJSjNlWX8UKfVh-h1ebCe0MEGqKzArNJ6x0nmta0oFMcWMyR6Cn2saR-oHvU8WrtUMEr-w020mAjvhfYav4EdT3GOGtaFgnbVkIs73iIMtr8Z-Y6mDEzqRzNzVRMLghj7CyWRCNJEk0jwWjOuC8FH4UsfHmtw3ouMFomjwsNLY0",
19 scope: "oada.yield:all"
20 }
21};
22
23let expiredTokens = [
24 "vxQyUQYUT0E5akXN_3LEoaPWtChJzeFNItEFgjA0",
25 "884rtVKCffFihijcMh8Y_0X5NsA1Srcx9TjJQY3f",
26 "GjLyKjR5HalUrZxauMdXJ38169T8ad9UdMvyjmRK",
27 "_-sNNae6ElBMlrewfGPjjv9JnVcUaHxQdJ-9pE4j",
28 "F3ZFCKjrR2cJY2FxCLgbqyMP7B6ybDuSMRabw4xB",
29 "PWgfksVlpIxxXF0xDUWDbiLTmB-MwiGP5FcmKirX",
30 "OkJpZdAijFOIw88QOqtdLd0hjy_ZsPICGAnRymaS",
31 "jAhUhVHhOKZ50K_B15_DrSYBBif2Noc9zTFYzY_5",
32 "iDuhpzZ-FxB2RkICfmO0vclG3sb2kYLuQtc_NZ9x",
33 "fdw3tuShJ-V-9AvAz2Af7lny_svkepl2TsrzcJX3",
34 "PIk8DfHGqXrPEdUxpL7sLsvBzptFSQnEHcqsssjb",
35 "OlJYiDGKbiw6B9epTE5NcmUmSoadseEnMycdC4io",
36 "q6so77ocgiLwOceTXocBpK6r4C6Gp3LG-pRmjwiF",
37 "2KYa_M-1UfZVNapZN3YpGMkKH623ZMH4jrQ320YT"
38];
39
40describe("~~~~Testing with expired tokens -> PUTs ~~~~~~~", async function() {
41 this.timeout(connectTime);
42 for (let i = 0; i < nTests; i++) {
43 before(
44 "Make the connection with a valid but expired token. Cache + websockets enabled.",
45 async function() {
46 expiredConnections[i] = await oada.connect({
47 domain,
48 options: connectionParameters.options,
49 token: expiredTokens[i]
50 });
51 }
52 );
53 } //for
54
55 for (let i = 0; i < nTests; i++) {
56 it(`Token [${i}]. Should create/put a resource after renewing the token.`, async function() {
57 this.timeout(connectTime);
58 var response = await expiredConnections[i].put({
59 path: `/bookmarks/test/test${i}/sometest`,
60 data: { _type: "application/json" }
61 });
62 expect(response.status).to.equal(status.NO_CONTENT);
63 });
64 } //for
65
66 for (let i = 0; i < nTests; i++) {
67 it(`Token [${i}]. Should not renew token for the subsequent PUTs.`, async function() {
68 this.timeout(connectTime);
69 var response = await expiredConnections[i].put({
70 path: `/bookmarks/test/test${i}/secondput${i}`,
71 data: { _type: "application/json" }
72 });
73 expect(response.status).to.equal(status.NO_CONTENT);
74 });
75 } //for
76
77 for (let i = 0; i < nTests; i++) {
78 it(`Token [${i}]. Should not renew token for the GETs.`, async function() {
79 this.timeout(connectTime);
80 var response = await expiredConnections[i].get({
81 path: `/bookmarks/test/test${i}`
82 });
83 expect(response.status).to.equal(status.OK);
84 });
85 } //for
86
87 for (let i = 0; i < nTests; i++) {
88 it(`Token [${i}]. Should not renew token for the DELs.`, async function() {
89 this.timeout(connectTime);
90 var response = await expiredConnections[i].delete({
91 path: `/bookmarks/test/test${i}`
92 });
93 expect(response.status).to.equal(status.NO_CONTENT);
94 });
95 } //for
96});
97
98describe("~~~~Testing with expired tokens -> GETs ~~~~~~~", async function() {
99 this.timeout(connectTime);
100 for (let i = nTests; i < 2 * nTests; i++) {
101 before(
102 "Make the connection with a valid but expired token. Cache + websockets enabled.",
103 async function() {
104 expiredConnections[i] = await oada.connect({
105 domain,
106 options: connectionParameters.options,
107 token: expiredTokens[i]
108 });
109 }
110 );
111 } //for
112
113 for (let i = nTests; i < 2 * nTests; i++) {
114 it(`Token [${i}]. Should GET a resource after renewing the token.`, async function() {
115 this.timeout(connectTime);
116 var response = await expiredConnections[i].get({
117 path: `/bookmarks/test`
118 });
119 expect(response.status).to.equal(status.OK);
120 });
121 } //for
122
123 for (let i = nTests; i < 2 * nTests; i++) {
124 it(`Token [${i}]. Should not renew token for the subsequent GETs.`, async function() {
125 this.timeout(connectTime);
126 var response = await expiredConnections[i].get({
127 path: `/bookmarks/test`
128 });
129 expect(response.status).to.equal(status.OK);
130 });
131 } //for
132});