mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
make internal note of which endpoints need testing
This commit is contained in:
parent
a4be5b4fd7
commit
7a4a3b5ef3
1 changed files with 97 additions and 25 deletions
|
@ -1,41 +1,113 @@
|
||||||
var assert = require("assert")
|
var assert = require('assert')
|
||||||
supertest = require('supertest'),
|
supertest = require('supertest'),
|
||||||
|
fs = require('fs'),
|
||||||
api = supertest('http://localhost:9001');
|
api = supertest('http://localhost:9001');
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
describe('Array', function(){
|
var filePath = path.join(__dirname, '../../../APIKEY.txt');
|
||||||
describe('#indexOf()', function(){
|
|
||||||
it('should return -1 when the value is not present', function(){
|
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
|
||||||
assert.equal(-1, [1,2,3].indexOf(5));
|
var apiVersion = 1;
|
||||||
assert.equal(-1, [1,2,3].indexOf(0));
|
var testPadId = makeid();
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Connectivity', function(){
|
describe('Connectivity', function(){
|
||||||
it('errors if can not connect', function(done) {
|
it('errors if can not connect', function(done) {
|
||||||
api.get('/api/')
|
api.get('/api/')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, done)
|
.expect(200, done)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('API Versioning', function(){
|
||||||
|
it('errors if can not connect', function(done) {
|
||||||
|
api.get('/api/')
|
||||||
|
.expect(function(res){
|
||||||
|
apiVersion = res.body.currentVersion;
|
||||||
|
if (!res.body.currentVersion) throw new Error("No version set in API");
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.expect(200, done)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Permission', function(){
|
||||||
|
it('errors if can connect without correct APIKey', function(done) {
|
||||||
|
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
|
||||||
|
// If your APIKey is password you deserve to fail all tests anyway
|
||||||
|
throw new Error("Erroring anyway just because the API seems broken here");
|
||||||
|
api.get('/api/'+apiVersion+'/createPad&apikey=password&padID=test')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200, done)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('createPad', function(){
|
||||||
|
it('creates a new pad', function(done) {
|
||||||
|
api.get(endPoint('createPad')+"&padID="+testPadId)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200, done)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Endpoints to interact with..
|
||||||
|
createPad(padID [, text])
|
||||||
|
getRevisions(padID)
|
||||||
|
padUsersCount(padID)
|
||||||
|
deletePad(padID)
|
||||||
|
getReadOnlyID(padID)
|
||||||
|
setPublicStatus(padID, publicStatus)
|
||||||
|
getPublicStatus(padID)
|
||||||
|
setPassword(padID, password)
|
||||||
|
isPasswordProtected(padID)
|
||||||
|
listAuthorsOfPad(padID)
|
||||||
|
getLastEdited(padID)
|
||||||
|
getHTML(padID, [rev])
|
||||||
|
setText(padID, text)
|
||||||
|
getText(padID, [rev])
|
||||||
|
|
||||||
|
listSessionsOfGroup(groupID)
|
||||||
|
getSessionInfo(sessionID)
|
||||||
|
deleteSession(sessionID)
|
||||||
|
createSession(groupID, authorID, validUntil)
|
||||||
|
|
||||||
|
listPadsOfAuthor(authorID)
|
||||||
|
createAuthorIfNotExistsFor(authorMapper [, name])
|
||||||
|
createAuthor([name])
|
||||||
|
|
||||||
|
createGroupPad(groupID, padName [, text])
|
||||||
|
listPads(groupID)
|
||||||
|
deleteGroup(groupID)
|
||||||
|
createGroupIfNotExistsFor(groupMapper)
|
||||||
|
createGroup()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
describe('Authentication', function() {
|
describe('getRevisionsCount', function(){
|
||||||
|
it('gets the revision counts of a new pad', function(done) {
|
||||||
it('errors if wrong basic auth', function(done) {
|
// This is broken because Etherpad doesn't handle HTTP codes properly see #2$
|
||||||
api.get('/blog')
|
// If your APIKey is password you deserve to fail all tests anyway
|
||||||
.set('x-api-key', '123myapikey')
|
api.get(endPoint('getRevisionsCount')+"&padID="+testPadId)
|
||||||
.auth('incorrect', 'credentials')
|
.expect('Content-Type', /json/)
|
||||||
.expect(401, done)
|
.expect(function(res){
|
||||||
|
console.log(res.body);
|
||||||
|
})
|
||||||
|
.expect(200, done)
|
||||||
});
|
});
|
||||||
|
})
|
||||||
it('errors if bad x-api-key header', function(done) {
|
|
||||||
api.get('/blog')
|
|
||||||
.auth('correct', 'credentials')
|
|
||||||
.expect(401)
|
|
||||||
.expect({error:"Bad or missing app identification header"}, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var endPoint = function(point){
|
||||||
|
return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeid()
|
||||||
|
{
|
||||||
|
var text = "";
|
||||||
|
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
|
for( var i=0; i < 5; i++ ){
|
||||||
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue