Page MenuHomeWickedGov Phorge

ext.centralauth.ForeignApi.test.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

ext.centralauth.ForeignApi.test.js

QUnit.module( 'ext.centralauth.ForeignApi', QUnit.newMwEnvironment( {
beforeEach: function () {
this.server = this.sandbox.useFakeServer();
this.server.respondImmediately = true;
}
} ) );
QUnit.test( 'Anonymous users do not get centralauthtoken', function ( assert ) {
mw.config.set( 'wgUserName', null );
this.server.respond( ( request ) => {
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
const api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
const spy = this.sandbox.spy( api, 'getCentralAuthToken' );
return api.get( {} ).then( () => {
assert.false( spy.called, 'Not called' );
} );
} );
QUnit.test( 'Logged in users get centralauthtoken if not logged in remotely', function ( assert ) {
mw.config.set( 'wgUserName', 'User' );
this.sandbox.stub( mw.ForeignApi.prototype, 'checkForeignLogin' ).returns(
$.Deferred().reject()
);
this.server.respond( ( request ) => {
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
const api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
const spy = this.sandbox.stub( api, 'getCentralAuthToken' ).returns(
$.Deferred().resolve( 'CENTRALAUTHTOKEN' )
);
return api.get( {} ).then( () => {
assert.true( spy.called, 'Called' );
} );
} );
QUnit.test( 'Logged in users do not get centralauthtoken if logged in remotely', function ( assert ) {
mw.config.set( 'wgUserName', 'User' );
this.sandbox.stub( mw.ForeignApi.prototype, 'checkForeignLogin' ).returns(
$.Deferred().resolve()
);
this.server.respond( ( request ) => {
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
const api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
const spy = this.sandbox.stub( api, 'getCentralAuthToken' ).returns(
$.Deferred().resolve( 'CENTRALAUTHTOKEN' )
);
return api.get( {} ).then( () => {
assert.false( spy.called, 'Called' );
} );
} );

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 22, 11:59 (2 h, 34 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
82/b6/283e3979cc66b256384198c1ce56
Default Alt Text
ext.centralauth.ForeignApi.test.js (1 KB)

Event Timeline