Merge "Move final batch of tests from api-testing to core"

This commit is contained in:
jenkins-bot 2020-06-08 19:37:11 +00:00 committed by Gerrit Code Review
commit 12e424bb78
3 changed files with 301 additions and 1 deletions

View file

@ -378,4 +378,50 @@ describe( 'The edit action', function testEditAction() {
}, 'POST' );
assert.equal( error.code, 'badmd5' );
} );
it( 'should override the text parameter with the appendtext parameter', async () => {
const page = utils.title( 'Page_' );
const text = 'A text that is to be overriden';
const bottom = 'This text should override the text parameter';
await Clark.edit( page, {
text: text,
appendtext: bottom
} );
const pageContent = await Clark.getHtml( page );
assert.notInclude( pageContent, text );
assert.include( pageContent, bottom );
} );
it( 'should override the text parameter with the prependtext parameter', async () => {
const page = utils.title( 'Page_' );
const text = 'A text that is to be overriden';
const top = 'This text should override the text parameter';
await Clark.edit( page, {
text: text,
prependtext: top
} );
const pageContent = await Clark.getHtml( page );
assert.notInclude( pageContent, text );
assert.include( pageContent, top );
} );
it( 'should override the text parameter with the appendtext and prependtext parameters', async () => {
const page = utils.title( 'Page_' );
const text = 'A text that is to be overriden';
const top = 'This text should override the text parameter on top';
const bottom = 'This text should override the text parameter at the end';
await Clark.edit( page, {
text: text,
prependtext: top,
appendtext: bottom
} );
const pageContent = await Clark.getHtml( page );
assert.notInclude( pageContent, text );
assert.include( pageContent, top + bottom );
} );
} );

View file

@ -4,15 +4,66 @@ const { action, assert, utils } = require( 'api-testing' );
describe( 'Test page protection levels and effectiveness', function () {
// users
let admin, wikiUser;
let admin, wikiUser, eve, root;
const anonymousUser = action.getAnon();
const protectedPage = utils.title( 'Protected_' );
const semiProtectedPage = utils.title( 'SemiProtected_' );
const testWatchlist = utils.title( 'TestWatchlist_' );
const testForExpiry = async ( expiry ) => {
const adminEditToken = await admin.token();
const token = await wikiUser.token();
const title = utils.title( 'TestExpiry_' );
await admin.edit( title, {
text: 'Test for Expiry'
} );
await admin.action( 'protect', {
title,
token: adminEditToken,
expiry: expiry,
protections: 'edit=sysop'
}, 'POST' );
const editPage = await wikiUser.actionError( 'edit', {
title,
token,
text: 'wikiUser editing protected page'
}, 'POST' );
return editPage.code;
};
const protectWithWatchParam = async ( watchedBefore, watchlistParam, title ) => {
const watchArgs = {
title: title,
token: await eve.token( 'watch' )
};
if ( watchedBefore !== 'watched' ) {
watchArgs.unwatch = true;
}
await eve.action( 'watch', watchArgs, 'POST' );
const token = await eve.token();
await eve.action( 'protect', {
title,
token,
protections: 'edit=autoconfirmed',
watchlist: watchlistParam
}, 'POST' );
const res = await eve.action( 'query', {
list: 'watchlistraw',
wrfromtitle: title,
wrtotitle: title
} );
return res.watchlistraw;
};
before( async () => {
admin = await action.mindy();
wikiUser = await action.alice();
eve = action.getAnon();
await eve.account( 'Eve' );
root = await action.root();
await root.addGroups( eve.username, [ 'sysop' ] );
// Get edit token for admin
const adminEditToken = await admin.token();
@ -23,6 +74,11 @@ describe( 'Test page protection levels and effectiveness', function () {
// Create SemiProtected page
await admin.edit( semiProtectedPage, { text: 'Semi Protected Page' } );
// Create TestWatchlist page
await eve.edit( testWatchlist, {
text: 'Protecting this page'
} );
// Add edit protections to only allow members of sysop group to edit Protected page
const addSysopProtection = await admin.action( 'protect', { title: protectedPage, token: adminEditToken, protections: 'edit=sysop' }, 'POST' );
assert.equal( addSysopProtection.protect.protections[ 0 ].edit, 'sysop' );
@ -76,4 +132,84 @@ describe( 'Test page protection levels and effectiveness', function () {
assert.equal( editPage.code, 'protectedpage' );
} );
it( 'should apply protections to a page for an indefinite duration', async () => {
const errorCode = await testForExpiry( 'indefinite' );
assert.equal( errorCode, 'protectedpage' );
} );
it( 'should apply protections to a page for an infinite duration', async () => {
const errorCode = await testForExpiry( 'infinite' );
assert.equal( errorCode, 'protectedpage' );
} );
it( 'should apply protections to a page for an infinity duration', async () => {
const errorCode = await testForExpiry( 'infinity' );
assert.equal( errorCode, 'protectedpage' );
} );
it( 'should apply protections to a page for some centuries to come', async () => {
const errorCode = await testForExpiry( '9999-01-01T00:00:00Z' );
assert.equal( errorCode, 'protectedpage' );
} );
it( 'protect a page for an infinite time to allow only autoconfirmed users to edit it and only sysops to move it', async () => {
const adminEditToken = await admin.token();
const token = await anonymousUser.token();
const title = utils.title( 'TestExpiry_' );
await admin.edit( title, {
text: 'Test for Expiry'
} );
await admin.action( 'protect', {
title,
token: adminEditToken,
expiry: 'infinite',
protections: 'edit=autoconfirmed|move=sysop'
}, 'POST' );
const editPage = await anonymousUser.actionError( 'edit', {
title,
token,
text: 'wikiUser editing protected page'
}, 'POST' );
const movePage = await anonymousUser.actionError( 'move', {
from: title,
to: 'Page with new Title',
token,
reason: 'to test that the page cannot be moved by a wikiUser'
}, 'POST' );
assert.equal( editPage.code, 'protectedpage' );
assert.equal( movePage.code, 'cantmove-anon' );
} );
it( 'should confirm that a user has created and edited pages on users watchlist by default', async () => {
const list = await eve.action( 'query', {
list: 'watchlistraw',
wrfromtitle: testWatchlist,
wrtotitle: testWatchlist
} );
assert.sameTitle( list.watchlistraw[ 0 ].title, testWatchlist );
} );
it( 'should test that a user has created and edited pages on users watchlist when the watchlist parameter is set to preferences', async () => {
const list = await protectWithWatchParam( 'watched', 'preferences', testWatchlist );
assert.sameTitle( list[ 0 ].title, testWatchlist );
} );
it( 'should test that the nochange parameter does not change the pages on the watchlist', async () => {
const list = await protectWithWatchParam( 'watched', 'nochange', testWatchlist );
assert.sameTitle( list[ 0 ].title, testWatchlist );
} );
it( 'should remove a page from the users watchlist and check that an empty array is returned if the page is the only page on the users watchlist', async () => {
const list = await protectWithWatchParam( 'watched', 'unwatch', testWatchlist );
assert.isEmpty( list );
} );
it( 'should add a page to the users watchlist', async () => {
const list = await protectWithWatchParam( 'unwatched', 'watch', semiProtectedPage );
assert.sameTitle( list[ 0 ].title, semiProtectedPage );
} );
} );

View file

@ -72,4 +72,122 @@ describe( 'The rollback action', function testEditRollback() {
assert.equal( error.code, 'permissiondenied' );
} );
it( 'should undo the last edit on the page using the pageid parameter', async () => {
const title = utils.title( 'Rollback_' );
const firstEdit = await alice.edit( title, { text: 'One', summary: 'first' } );
const secondEdit = await bob.edit( title, { text: 'Two', summary: 'second' } );
const result = await mindy.action( 'rollback', {
pageid: firstEdit.pageid,
user: bob.username,
summary: 'revert',
token: await mindy.token( 'rollback' )
}, 'POST' );
const rev = await mindy.getRevision( title );
assert.sameTitle( result.rollback.title, title );
assert.equal( result.rollback.old_revid, secondEdit.newrevid );
assert.equal( rev.revid, result.rollback.revid );
} );
it( 'should throw an error with code missingparam when neither pageid nor title is provided for a rollback action', async () => {
const title = utils.title( 'Rollback_' );
await alice.edit( title, { text: 'One', summary: 'first' } );
await bob.edit( title, { text: 'Two', summary: 'second' } );
const error = await mindy.actionError( 'rollback', {
user: bob.username,
summary: 'revert',
token: await mindy.token( 'rollback' )
}, 'POST' );
assert.equal( error.code, 'missingparam' );
} );
it( 'should throw an error with code notoken when the token parameter is not provided for a rollback action', async () => {
const title = utils.title( 'Rollback_' );
await alice.edit( title, { text: 'One', summary: 'first' } );
await bob.edit( title, { text: 'Two', summary: 'second' } );
const error = await mindy.actionError( 'rollback', {
title: title,
user: bob.username,
summary: 'revert'
}, 'POST' );
assert.equal( error.code, 'missingparam' );
} );
it( 'should throw an error with code nouser when a user is not provided for a rollback action', async () => {
const title = utils.title( 'Rollback_' );
await alice.edit( title, { text: 'One', summary: 'first' } );
await bob.edit( title, { text: 'Two', summary: 'second' } );
const error = await mindy.actionError( 'rollback', {
title: title,
summary: 'revert',
token: await mindy.token( 'rollback' )
}, 'POST' );
assert.equal( error.code, 'missingparam' );
} );
it( 'should throw an error with code onlyauthor if the page has only one author', async () => {
const title = utils.title( 'Rollback_' );
await alice.edit( title, { text: 'One', summary: 'first' } );
const error = await mindy.actionError( 'rollback', {
title: title,
user: alice.username,
summary: 'revert',
token: await mindy.token( 'rollback' )
}, 'POST' );
assert.equal( error.code, 'onlyauthor' );
} );
it( 'should throw an error with code mustpostparams when the request to the API is not a post request', async () => {
const title = utils.title( 'Rollback_' );
await alice.edit( title, { text: 'One', summary: 'first' } );
await bob.edit( title, { text: 'Two', summary: 'second' } );
const error = await mindy.actionError( 'rollback', {
title: title,
user: bob.username,
summary: 'revert',
token: await mindy.token( 'rollback' )
} );
assert.equal( error.code, 'mustpostparams' );
} );
it( 'should mark the revert as a bot edit', async () => {
const title = utils.title( 'Rollback_' );
const firstEdit = await alice.edit( title, { text: 'One', summary: 'first' } );
const secondEdit = await bob.edit( title, { text: 'Two', summary: 'second' } );
const result = await mindy.action( 'rollback', {
pageid: firstEdit.pageid,
user: bob.username,
summary: 'revert',
markbot: true,
token: await mindy.token( 'rollback' )
}, 'POST' );
const recentChanges = await mindy.getChangeEntry( { rctitle: title } );
assert.exists( recentChanges.bot );
assert.sameTitle( result.rollback.title, title );
assert.equal( result.rollback.old_revid, secondEdit.newrevid );
assert.equal( recentChanges.revid, result.rollback.revid );
} );
} );