-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 subscriber: sanitize email vol. 2 (#8280)
no issue 🐛 subscriber: sanitize email vol. 2 - ensure email get's sanitized for every error case 🐛 validator.isEmptyOrURL doesn't accept non strings - otherwise it shows a weird error message in the client ✨ new tests for subscriber app - routing tests * change tests for Ghost 1.0 * it took me 15min to find this 😡
- Loading branch information
Showing
5 changed files
with
133 additions
and
24 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 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,122 @@ | ||
var supertest = require('supertest'), | ||
should = require('should'), | ||
sinon = require('sinon'), | ||
testUtils = require('../../../../test/utils'), | ||
labs = require('../../../utils/labs'), | ||
config = require('../../../config'), | ||
ghost = testUtils.startGhost, | ||
sandbox = sinon.sandbox.create(); | ||
|
||
describe('Subscriber: Routing', function () { | ||
var ghostServer, request; | ||
|
||
before(function (done) { | ||
ghost().then(function (_ghostServer) { | ||
ghostServer = _ghostServer; | ||
return ghostServer.start(); | ||
}).then(function () { | ||
request = supertest.agent(config.get('url')); | ||
done(); | ||
}).catch(function (e) { | ||
console.log('Ghost Error: ', e); | ||
console.log(e.stack); | ||
done(e); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
return ghostServer.stop(); | ||
}); | ||
|
||
before(function () { | ||
sandbox.stub(labs, 'isSet', function (key) { | ||
if (key === 'subscribers') { | ||
return true; | ||
} | ||
}); | ||
}); | ||
|
||
after(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('GET', function () { | ||
it('[success]', function (done) { | ||
request.get('/subscribe/') | ||
.expect(200) | ||
.end(function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('POST', function () { | ||
it('[success]', function (done) { | ||
request.post('/subscribe/') | ||
.set('Content-type', 'application/x-www-form-urlencoded') | ||
.send({ | ||
email: 'test@ghost.org', | ||
location: 'http://localhost:2368', | ||
confirm: '' | ||
}) | ||
.expect(200) | ||
.end(function (err, res) { | ||
should.not.exist(err); | ||
res.text.should.containEql('Subscribed!'); | ||
res.text.should.containEql('test@ghost.org'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[error] email is invalid', function (done) { | ||
request.post('/subscribe/') | ||
.set('Content-type', 'application/x-www-form-urlencoded') | ||
.send({ | ||
email: 'alphabetazeta', | ||
location: 'http://localhost:2368', | ||
confirm: '' | ||
}) | ||
.expect(200) | ||
.end(function (err, res) { | ||
should.not.exist(err); | ||
res.text.should.containEql('http://localhost:2368'); | ||
res.text.should.not.containEql('Subscribed!'); | ||
res.text.should.not.containEql('alphabetazeta'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[error] location is not defined', function (done) { | ||
request.post('/subscribe/') | ||
.set('Content-type', 'application/x-www-form-urlencoded') | ||
.send({ | ||
email: 'test@ghost.org', | ||
confirm: '' | ||
}) | ||
.expect(200) | ||
.end(function (err, res) { | ||
should.not.exist(err); | ||
res.text.should.not.containEql('Subscribed!'); | ||
res.text.should.not.containEql('test@ghost.org'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[error] confirm is not defined', function (done) { | ||
request.post('/subscribe/') | ||
.set('Content-type', 'application/x-www-form-urlencoded') | ||
.send({ | ||
email: 'test@ghost.org', | ||
location: 'http://localhost:2368' | ||
}) | ||
.expect(200) | ||
.end(function (err, res) { | ||
should.not.exist(err); | ||
res.text.should.not.containEql('Subscribed!'); | ||
res.text.should.not.containEql('test@ghost.org'); | ||
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
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