-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added specs and implementation for online resolver.
- Loading branch information
Showing
8 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
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,12 +1,11 @@ | ||
import {OptionsWithUrl} from 'request'; | ||
|
||
import {IUserCredentials} from './../interfaces/IUserCredentials'; | ||
import {IOAuthCredentials} from './../interfaces/IOAuthCredentials'; | ||
import {IEnvironment} from './../interfaces/IEnvironment'; | ||
|
||
export interface IAuthOptions { | ||
options: OptionsWithUrl; | ||
credentials: IUserCredentials | IOAuthCredentials; | ||
credentials: IUserCredentials; | ||
env: IEnvironment; | ||
} | ||
|
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {expect} from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import {SinonStub} from 'sinon'; | ||
import * as consts from 'constants'; | ||
|
||
import {IAuthOptions} from './../../src/core/auth/IAuthOptions'; | ||
import {IUserCredentials} from './../../src/core/interfaces/IUserCredentials'; | ||
import {OnlineResolver} from './../../src/core/auth/OnlineResolver'; | ||
|
||
let creds: IUserCredentials = { | ||
username: 'user', | ||
password: 'pass' | ||
}; | ||
|
||
let onlineOptions: IAuthOptions = { | ||
credentials: creds, | ||
options: { | ||
url: 'https://sp2013dev.sharepoint.com/sites/dev/_api' | ||
}, | ||
env: undefined | ||
}; | ||
|
||
let authResponse: any = { | ||
FedAuth: 'fedauth', | ||
rtFa: 'rtfa' | ||
}; | ||
|
||
let cookieString: string = `FedAuth=${authResponse.FedAuth}; rtFa=${authResponse.rtFa}`; | ||
|
||
describe('sp-request: OnlineResolver tests', () => { | ||
let resolver: OnlineResolver; | ||
let siginStup: SinonStub; | ||
|
||
beforeEach(() => { | ||
let resolverModule: any = require('./../../src/core/auth/OnlineResolver'); | ||
resolver = new resolverModule.OnlineResolver(onlineOptions); | ||
let sp: any = require('node-spoauth'); | ||
siginStup = sinon.stub(sp.RestService.prototype, 'signin'); | ||
}); | ||
|
||
afterEach(() => { | ||
siginStup.restore(); | ||
}); | ||
|
||
it('should set cookie header', (done) => { | ||
siginStup.callsArgWith(2, null, { | ||
FedAuth: 'fedauth', | ||
rtFa: 'rtfa' | ||
}); | ||
|
||
resolver.ApplyAuthHeaders() | ||
.then((options) => { | ||
expect(options.headers['Cookie']).to.equal(cookieString); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('should set secureOptions', (done) => { | ||
siginStup.callsArgWith(2, null, { | ||
FedAuth: 'fedauth', | ||
rtFa: 'rtfa' | ||
}); | ||
|
||
resolver.ApplyAuthHeaders() | ||
.then((options) => { | ||
expect(options['secureOptions']).to.equal(consts.SSL_OP_NO_TLSv1_2); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('should throws en error', (done) => { | ||
let error: string = 'error'; | ||
siginStup.throws(error); | ||
|
||
resolver.ApplyAuthHeaders() | ||
.then((options) => { | ||
// | ||
}) | ||
.catch((err) => { | ||
expect(err.name).to.equal(error); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,3 +1,4 @@ | ||
import './SPRequest.spec'; | ||
import './AuthResolverFactory.spec'; | ||
import './OnPremResolver.spec'; | ||
import './OnlineResolver.spec'; |