Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 0959cb7

Browse files
author
fireice.topcoder
committed
Flag Web Arena Super User Role
1 parent fb1d9ab commit 0959cb7

File tree

6 files changed

+55
-31
lines changed

6 files changed

+55
-31
lines changed

initializers/middleware.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ exports.middleware = function (api, next) {
114114
return;
115115
}
116116
var split = decoded.sub.split("|");
117-
if (split.length == 1) {
117+
if (split.length === 1) {
118118
// token.sub should contain "|"
119119
cb(new IllegalArgumentError('Malformed Auth header. token.sub is in bad format!'));
120120
return;
121121
}
122122
try {
123-
socialUserId = (split[split.length-1] || "").trim();
123+
socialUserId = (split[split.length - 1] || "").trim();
124124
socialProvider = (split[0] || "").trim();
125125
} catch (ignored) {
126126
cb(new IllegalArgumentError('Malformed Auth header. Could not parse token.sub!'));
@@ -180,6 +180,9 @@ exports.middleware = function (api, next) {
180180
},
181181
isAdmin: function (cbk) {
182182
api.dataAccess.executeQuery("check_is_admin", {user_id: userId}, connectionMap, cbk);
183+
},
184+
isWebArenaSuper: function (cbk) {
185+
api.dataAccess.executeQuery("check_is_web_arena_super", { user_id: userId }, connectionMap, cbk);
183186
}
184187
}, cbx);
185188
}, function (results, cbx) {
@@ -198,6 +201,7 @@ exports.middleware = function (api, next) {
198201
} else {
199202
userInfo.accessLevel = "member";
200203
}
204+
userInfo.isWebArenaSuper = results.isWebArenaSuper[0].count === 1;
201205
cbx(null, userInfo);
202206
}
203207
], cb);

queries/check_is_web_arena_super

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT COUNT(*) AS count
2+
FROM informixoltp:group_user
3+
WHERE user_id = @user_id@
4+
AND group_id = 60

queries/check_is_web_arena_super.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "check_is_web_arena_super",
3+
"db" : "common_oltp",
4+
"sqlfile" : "check_is_web_arena_super"
5+
}

test/sqls/oauth/common_oltp__clean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
DELETE user_social_login where user_id in (400000, 400001);
22
DELETE user_role_xref where user_role_id in (400000);
33
DELETE security_user where login_id in (400001);
4-
DELETE user where user_id in (400000, 400001);
4+
DELETE user where user_id in (400000, 400001);

test/sqls/oauth/common_oltp__insert_test_data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id,
1717
INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('git123456', 400001,4, 'user2');
1818

1919
INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('sf1234', 400000, 5, 'user1');
20-
INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('sf123456', 400001,5, 'user2');
20+
INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('sf123456', 400001,5, 'user2');

test/test.oauth.js

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/*
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.1
4+
* @version 1.2
55
* @author Sky_
66
* changes in 1.1:
77
* - add tests for Create Token api
8+
* changes in 1.2:
9+
* - Update tests to support isWebArenaSuper field.
810
*/
911
"use strict";
1012
/*global describe, it, before, beforeEach, after, afterEach */
@@ -43,9 +45,10 @@ describe('Test Oauth', function () {
4345
adminSubSalesforce = "salesforce-oauth|sf123456",
4446
userSubAD = "ad|400000",
4547
adminSubAD = "ad|400001",
46-
notFoundSub = "google-oauth|458965118758";
47-
var jwtToken = "";
48-
var jwtTokenCookieKey = process.env.JWT_TOKEN_COOKIE_KEY;
48+
webArenaSuper = "ad|124861",
49+
notFoundSub = "google-oauth|458965118758",
50+
jwtToken = "",
51+
jwtTokenCookieKey = process.env.JWT_TOKEN_COOKIE_KEY;
4952

5053

5154
/**
@@ -217,121 +220,129 @@ describe('Test Oauth', function () {
217220
*/
218221
it('should be authorized as member (google)', function (done) {
219222
var oauth = generateAuthHeader({ sub: userSubGoogle });
220-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
223+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
221224
});
222225

223226
/**
224227
* /test/oauth/ with header
225228
*/
226229
it('should be authorized as member (facebook)', function (done) {
227230
var oauth = generateAuthHeader({ sub: userSubFacebook });
228-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
231+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
229232
});
230233

231234
/**
232235
* /test/oauth/ with header
233236
*/
234237
it('should be authorized as member (twitter)', function (done) {
235238
var oauth = generateAuthHeader({ sub: userSubTwitter });
236-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
239+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
237240
});
238241

239242
/**
240243
* /test/oauth/ with header
241244
*/
242245
it('should be authorized as member (github)', function (done) {
243246
var oauth = generateAuthHeader({ sub: userSubGithub });
244-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
247+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
245248
});
246249

247250
/**
248251
* /test/oauth/ with header
249252
*/
250253
it('should be authorized as member (salesforce)', function (done) {
251254
var oauth = generateAuthHeader({ sub: userSubSalesforce });
252-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
255+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
253256
});
254257

255258
/**
256259
* /test/oauth/ with header
257260
*/
258261
it('should be authorized as member (ad)', function (done) {
259262
var oauth = generateAuthHeader({ sub: userSubAD});
260-
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user"}, oauth, done);
263+
assertResponse({accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false }, oauth, done);
261264
});
262265

263266
/**
264267
* /test/oauth/ with header
265268
*/
266269
it('should be authorized as admin (google)', function (done) {
267270
var oauth = generateAuthHeader({ sub: adminSubGoogle});
268-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
271+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
269272
});
270273

271274
/**
272275
* /test/oauth/ with header
273276
*/
274277
it('should be authorized as admin (facebook)', function (done) {
275278
var oauth = generateAuthHeader({ sub: adminSubFacebook});
276-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
279+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
277280
});
278281

279282
/**
280283
* /test/oauth/ with header
281284
*/
282285
it('should be authorized as admin (twitter)', function (done) {
283286
var oauth = generateAuthHeader({ sub: adminSubTwitter});
284-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
287+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
285288
});
286289

287290
/**
288291
* /test/oauth/ with header
289292
*/
290293
it('should be authorized as admin (github)', function (done) {
291294
var oauth = generateAuthHeader({ sub: adminSubGithub});
292-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
295+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
293296
});
294297

295298
/**
296299
* /test/oauth/ with header
297300
*/
298301
it('should be authorized as admin (salesforce)', function (done) {
299302
var oauth = generateAuthHeader({ sub: adminSubSalesforce});
300-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
303+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
301304
});
302305

303306
/**
304307
* /test/oauth/ with header
305308
*/
306309
it('should be authorized as admin (ad)', function (done) {
307310
var oauth = generateAuthHeader({ sub: adminSubAD});
308-
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user"}, oauth, done);
311+
assertResponse({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, oauth, done);
312+
});
313+
314+
/**
315+
* /test/oauth/ with web arena super user.
316+
*/
317+
it('should be authorized as member and web arena super', function (done) {
318+
var oauth = generateAuthHeader({ sub: webArenaSuper});
319+
assertResponse({accessLevel: "member", userId: 124861, handle: "ksmith", isWebArenaSuper: true }, oauth, done);
309320
});
310321

311322
/**
312323
* /test/oauth/ with header and cookie
313324
*/
314325
it('should be authorized as admin (ad) with both header and cookie', function (done) {
315-
var authHeader = generateAuthHeader({ sub: adminSubAD});
316-
var authCookie = generateAuthCookie({ sub: adminSubAD});
317-
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user"}, authHeader, authCookie, done);
326+
var authHeader = generateAuthHeader({ sub: adminSubAD}),
327+
authCookie = generateAuthCookie({ sub: adminSubAD});
328+
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, authHeader, authCookie, done);
318329
});
319330

320331
/**
321332
* /test/oauth/ with header and cookie
322333
*/
323334
it('should be authorized as admin (ad) with header but invalid cookie', function (done) {
324-
var authHeader = generateAuthHeader({ sub: adminSubAD});
325-
var authCookie = jwtTokenCookieKey + "=asd";
326-
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user"}, authHeader, authCookie, done);
335+
var authHeader = generateAuthHeader({ sub: adminSubAD}),
336+
authCookie = jwtTokenCookieKey + "=asd";
337+
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, authHeader, authCookie, done);
327338
});
328339

329340
/**
330341
* /test/oauth/ without header but with cookie
331342
*/
332343
it('should be authorized as admin (ad) without header but with cookie', function (done) {
333344
var authCookie = generateAuthCookie({ sub: adminSubAD});
334-
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user"}, null, authCookie, done);
345+
assertResponseWithCookie({accessLevel: "admin", userId: 400001, handle: "admin_user", isWebArenaSuper: false }, null, authCookie, done);
335346
});
336347

337348
/**
@@ -370,8 +381,8 @@ describe('Test Oauth', function () {
370381
* /test/oauth/ with invalid header but valid cookie
371382
*/
372383
it('should return error if header is invalid but cookie is valid', function (done) {
373-
var authHeader = generateAuthHeader({ sub: userSubGoogle});
374-
var authCookie = generateAuthCookie({ sub: userSubGoogle});
384+
var authHeader = generateAuthHeader({ sub: userSubGoogle}),
385+
authCookie = generateAuthCookie({ sub: userSubGoogle});
375386
assertErrorResponseWithCookie(400, authHeader + "asd", authCookie, "Malformed Auth header", done);
376387
});
377388

@@ -460,7 +471,7 @@ describe('Test Oauth', function () {
460471
*/
461472
it('should be authorized as member (salesforce) - cache version', function (done) {
462473
var oauth = generateAuthHeader({ sub: userSubSalesforce }),
463-
response = {accessLevel: "member", userId: 400000, handle: "normal_user"},
474+
response = {accessLevel: "member", userId: 400000, handle: "normal_user", isWebArenaSuper: false},
464475
fun = assertResponse.bind(this, response, oauth);
465476
async.waterfall([
466477
fun,
@@ -506,7 +517,7 @@ describe('Test Oauth', function () {
506517
.end(done);
507518
});
508519
});
509-
520+
510521
describe("Refresh Token api", function () {
511522

512523
/**

0 commit comments

Comments
 (0)