Skip to content

Commit 470f9ca

Browse files
authored
Allow cross domain authorization by default and add unit tests (#427)
* Allow cross origin auth by default and add units * Reverted unnecessary changes * removed extra lines * Remove asyncs * Bump version * Fix gitignore
1 parent 68f41f5 commit 470f9ca

File tree

8 files changed

+38
-280
lines changed

8 files changed

+38
-280
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _def
66
samples/*.js
77

88
# Tests
9-
test/**.js
9+
test/**/*.js
1010

1111
# Logs
1212
logs

api/handlers/basiccreds.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ifm = require('../interfaces/common/VsoBaseInterfaces');
55
import * as resthandlers from 'typed-rest-client/Handlers';
66

77
export class BasicCredentialHandler extends resthandlers.BasicCredentialHandler implements ifm.IRequestHandler {
8-
constructor(username: string, password: string, allowCrossOriginAuthentication?: boolean) {
8+
constructor(username: string, password: string, allowCrossOriginAuthentication: boolean = true) {
99
super(username, password, allowCrossOriginAuthentication);
1010
}
1111
}

api/handlers/bearertoken.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ifm = require('../interfaces/common/VsoBaseInterfaces');
55
import * as resthandlers from 'typed-rest-client/Handlers';
66

77
export class BearerCredentialHandler extends resthandlers.BearerCredentialHandler implements ifm.IRequestHandler {
8-
constructor(token: string, allowCrossOriginAuthentication?: boolean) {
8+
constructor(token: string, allowCrossOriginAuthentication: boolean = true) {
99
super(token, allowCrossOriginAuthentication);
1010
}
1111
}

api/handlers/personalaccesstoken.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ifm = require('../interfaces/common/VsoBaseInterfaces');
55
import * as resthandlers from 'typed-rest-client/Handlers';
66

77
export class PersonalAccessTokenCredentialHandler extends resthandlers.PersonalAccessTokenCredentialHandler implements ifm.IRequestHandler {
8-
constructor(token: string, allowCrossOriginAuthentication?: boolean) {
8+
constructor(token: string, allowCrossOriginAuthentication: boolean = true) {
99
super(token, allowCrossOriginAuthentication);
1010
}
1111
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "azure-devops-node-api",
33
"description": "Node client for Azure DevOps and TFS REST APIs",
4-
"version": "10.2.0",
4+
"version": "10.2.1",
55
"main": "./WebApi.js",
66
"types": "./WebApi.d.ts",
77
"scripts": {

test/units/tests.js

-274
This file was deleted.

test/units/tests.ts

+32
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,35 @@ describe('WebApi Units', function () {
299299
assert.equal(myWebApi.isNoProxyHost('https://my-other-tfs-instance.host/myproject'), false);
300300
});
301301
});
302+
303+
describe('Auth Handlers Units', function () {
304+
it('cross origin authenthication should be allowed by default in BasicCredentialHandler', () => {
305+
const basicAuthHandler = WebApi.getBasicHandler('user', 'password');
306+
assert(basicAuthHandler['allowCrossOriginAuthentication'] === true);
307+
});
308+
309+
it('cross origin authenthication should be allowed by default in BearerCredentialHandler', () => {
310+
const bearerAuthHandler = WebApi.getBearerHandler('0000000000000000000000000000000000000000');
311+
assert(bearerAuthHandler['allowCrossOriginAuthentication'] === true);
312+
});
313+
314+
it('cross origin authenthication should be allowed by default in PersonalAccessTokenCredentialHandler', () => {
315+
const personalAccessTokenAuthHandler = WebApi.getPersonalAccessTokenHandler('0000000000000000000000000000000000000000');
316+
assert(personalAccessTokenAuthHandler['allowCrossOriginAuthentication'] === true);
317+
});
318+
319+
it('cross origin authenthication could be disabled in BasicCredentialHandler', () => {
320+
const basicAuthHandler = WebApi.getBasicHandler('user', 'password', false);
321+
assert(basicAuthHandler['allowCrossOriginAuthentication'] === false);
322+
});
323+
324+
it('cross origin authenthication could be disabled in BearerCredentialHandler', () => {
325+
const bearerAuthHandler = WebApi.getBearerHandler('0000000000000000000000000000000000000000', false);
326+
assert(bearerAuthHandler['allowCrossOriginAuthentication'] === false);
327+
});
328+
329+
it('cross origin authenthication could be disabled in PersonalAccessTokenCredentialHandler', () => {
330+
const personalAccessTokenAuthHandler = WebApi.getPersonalAccessTokenHandler('0000000000000000000000000000000000000000', false);
331+
assert(personalAccessTokenAuthHandler['allowCrossOriginAuthentication'] === false);
332+
});
333+
});

0 commit comments

Comments
 (0)