123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- var chakram = require("./../setup.js").chakram;
- var expect = chakram.expect;
- var itPropagatesToTheApi = require("./../setup.js").itPropagatesToTheApi;
- var itShowsUpInPdnsAs = require("./../setup.js").itShowsUpInPdnsAs;
- var schemas = require("./../schemas.js");
- describe("API", function () {
- this.timeout(3000);
- before(function () {
- chakram.setRequestDefaults({
- headers: {
- 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
- },
- followRedirect: false,
- baseUrl: 'https://www/api/v1',
- })
- });
- it("provides an index page", function () {
- var response = chakram.get('/');
- return expect(response).to.have.status(200);
- });
- describe("user registration", function () {
- it("returns a user object", function () {
- var email, password, token;
- email = require("uuid").v4() + '@e2etest.local';
- password = require("uuid").v4();
- var response = chakram.post('/auth/users/create/', {
- "email": email,
- "password": password,
- });
- return expect(response).to.have.status(201);
- });
- it("locks new users that look suspicious");
- });
- describe("user account", function () {
- var email, password;
- before(function () {
- // register a user that we can work with
- email = require("uuid").v4() + '@e2etest.local';
- password = require("uuid").v4();
- var response = chakram.post('/auth/users/create/', {
- "email": email,
- "password": password,
- });
- return expect(response).to.have.status(201);
- });
- it("returns a token when logging in", function () {
- return chakram.post('/auth/token/create/', {
- "email": email,
- "password": password,
- }).then(function (loginResponse) {
- expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
- });
- });
- describe("auth/me/ endpoint", function () {
- var email2, password2, token2;
- before(function () {
- // register an independent user to screw around with
- email2 = require("uuid").v4() + '@e2etest.local';
- password2 = require("uuid").v4();
- return chakram.post('/auth/users/create/', {
- "email": email2,
- "password": password2,
- }).then(function () {
- return chakram.post('/auth/token/create/', {
- "email": email2,
- "password": password2,
- }).then(function (response) {
- token2 = response.body.auth_token
- });
- });
- });
- it("returns JSON of correct schema", function () {
- var response = chakram.get('/auth/me/', {
- headers: {'Authorization': 'Token ' + token2 }
- });
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.user);
- return chakram.wait();
- });
- it("allows changing email address", function () {
- let email3 = require("uuid").v4() + '@e2etest.local';
- return chakram.put('/auth/me/',
- {'email': email3},
- {headers: {'Authorization': 'Token ' + token2}}
- ).then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.user);
- expect(response.body.email).to.equal(email3);
- });
- });
- });
- describe("token management (djoser)", function () {
- var token1, token2;
- function createTwoTokens() {
- return chakram.waitFor([
- chakram.post('/auth/token/create/', {
- "email": email,
- "password": password,
- }).then(function (loginResponse) {
- expect(loginResponse).to.have.status(201);
- expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
- token1 = loginResponse.body.auth_token;
- expect(token1).to.not.equal(token2);
- }),
- chakram.post('/auth/token/create/', {
- "email": email,
- "password": password,
- }).then(function (loginResponse) {
- expect(loginResponse).to.have.status(201);
- expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
- token2 = loginResponse.body.auth_token;
- expect(token2).to.not.equal(token1);
- })
- ]);
- }
- function deleteToken(token) {
- var response = chakram.post('/auth/token/destroy/', null, {
- headers: {'Authorization': 'Token ' + token}
- });
- return expect(response).to.have.status(204);
- }
- it("can create additional tokens", createTwoTokens);
- describe("additional tokens", function () {
- before(createTwoTokens);
- it("can be used for login (1)", function () {
- return expect(chakram.get('/domains/', {
- headers: {'Authorization': 'Token ' + token1 }
- })).to.have.status(200);
- });
- it("can be used for login (2)", function () {
- return expect(chakram.get('/domains/', {
- headers: {'Authorization': 'Token ' + token2 }
- })).to.have.status(200);
- });
- describe("and one deleted", function () {
- before(function () {
- var response = chakram.post('/auth/token/destroy/', undefined,
- { headers: {'Authorization': 'Token ' + token1 } }
- );
- return expect(response).to.have.status(204);
- });
- it("leaves the other untouched", function () {
- return expect(chakram.get('/domains/', {
- headers: {'Authorization': 'Token ' + token2 }
- })).to.have.status(200);
- });
- });
- });
- });
- });
- var email = require("uuid").v4() + '@e2etest.local';
- describe("with user account [" + email + "]", function () {
- var apiHomeSchema = {
- properties: {
- domains: {type: "string"},
- logout: {type: "string"},
- user: {type: "string"},
- },
- required: ["domains", "logout", "user"]
- };
- var password, token;
- before(function () {
- chakram.setRequestSettings({
- headers: {
- 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
- },
- followRedirect: false,
- baseUrl: 'https://www/api/v1',
- });
- // register a user that we can login and work with
- password = require("uuid").v4();
- return chakram.post('/auth/users/create/', {
- "email": email,
- "password": password,
- }).then(function () {
- return chakram.post('/auth/token/create/', {
- "email": email,
- "password": password,
- }).then(function (loginResponse) {
- expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
- token = loginResponse.body.auth_token;
- chakram.setRequestHeader('Authorization', 'Token ' + token);
- });
- });
- });
- describe("(logged in)", function () {
- describe("api 'homepage'", function () {
- var response;
- before(function () {
- response = chakram.get('/');
- });
- it('has status 200', function () {
- return expect(response).to.have.status(200);
- });
- it('looks according to the schema', function () {
- return expect(response).to.have.schema(apiHomeSchema);
- });
- });
- describe("on domains/ endpoint", function () {
- var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
- before(function () {
- return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
- });
- it("can register a domain name", function () {
- var response = chakram.get('/domains/' + domain + '/');
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.domain);
- return chakram.wait();
- });
- describe("on rrsets/ endpoint", function () {
- it("can retrieve RRsets", function () {
- var response = chakram.get('/domains/' + domain + '/rrsets/');
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrsets);
- response = chakram.get('/domains/' + domain + '/rrsets/.../NS/');
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrset);
- return chakram.wait();
- });
- });
- });
- describe('POST rrsets/ with fresh domain', function () {
- var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
- before(function () {
- return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
- });
- describe("can set an A RRset", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
- );
- expect(response).to.have.status(201);
- expect(response).to.have.schema(schemas.rrset);
- expect(response).to.have.json('ttl', 60);
- expect(response).to.have.json('records', ['127.0.0.1']);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: '', domain: domain, type: 'A', ttl: 60, records: ['127.0.0.1']},
- ]);
- itShowsUpInPdnsAs('', domain, 'A', ['127.0.0.1'], 60);
- });
- describe("cannot create RRsets of restricted or dead type", function () {
- var rrTypes = ['DNAME', 'ALIAS', 'SOA', 'RRSIG', 'DNSKEY', 'NSEC3PARAM', 'OPT'];
- for (var i = 0; i < rrTypes.length; i++) {
- var rrType = rrTypes[i];
- it(rrType, function () {
- return expect(chakram.post(
- '/domains/' + domain + '/rrsets/',
- {'subname': 'not-welcome', 'type': rrType, 'records': ['127.0.0.1'], 'ttl': 60}
- )).to.have.status(400);
- });
- }
- });
- it("cannot update RRSets for nonexistent domain name", function () {
- return expect(chakram.patch(
- '/domains/nonexistent.e2e.domain/rrsets/',
- {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
- )).to.have.status(404);
- });
- it("cannot create RRSets for nonexistent domain name", function () {
- return expect(chakram.post(
- '/domains/nonexistent.e2e.domain/rrsets/',
- {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
- )).to.have.status(404);
- });
- it("cannot set unicode RRsets", function () {
- return expect(chakram.post(
- '/domains/' + domain + '/rrsets/',
- {'subname': '想不出来', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
- )).to.have.status(422);
- });
- describe("can set a wildcard AAAA RRset with multiple records", function () {
- before(function () {
- return chakram.post(
- '/domains/' + domain + '/rrsets/',
- {'subname': '*.foobar', 'type': 'AAAA', 'records': ['::1', 'bade::affe'], 'ttl': 60}
- );
- });
- itPropagatesToTheApi([
- {subname: '*.foobar', domain: domain, type: 'AAAA', ttl: 60, records: ['::1', 'bade::affe']},
- {subname: '*.foobar', domain: domain, type: 'AAAA', records: ['bade::affe', '::1']},
- ]);
- itShowsUpInPdnsAs('test.foobar', domain, 'AAAA', ['::1', 'bade::affe'], 60);
- });
- describe("can bulk-post an AAAA and an MX record", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
- { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
- ]
- );
- expect(response).to.have.status(201);
- expect(response).to.have.schema(schemas.rrsets);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
- {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
- ]);
- itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
- itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
- });
- describe("cannot bulk-post with missing or invalid fields", function () {
- before(function () {
- // Set an RRset that we'll try to overwrite
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
- );
- expect(response).to.have.status(201);
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
- {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
- {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
- {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
- {'subname': 'd.1', 'ttl': 50, 'type': 'SOA', 'records': ['ns1.desec.io. peter.desec.io. 2018034419 10800 3600 604800 60']},
- {'subname': 'd.1', 'ttl': 50, 'type': 'OPT', 'records': ['9999']},
- {'subname': 'd.1', 'ttl': 50, 'type': 'TYPE099', 'records': ['v=spf1 mx -all']},
- ]
- );
- expect(response).to.have.status(400);
- expect(response).to.have.json([
- { type: [ 'This field is required.' ] },
- { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
- {},
- { ttl: [ 'This field is required.' ] },
- { records: [ 'This field is required.' ] },
- { type: [ 'You cannot tinker with the SOA RRset.' ] },
- { type: [ 'You cannot tinker with the OPT RRset.' ] },
- { type: [ 'Generic type format is not supported.' ] },
- ]);
- return chakram.wait();
- });
- it("does not propagate partially to the API", function () {
- return chakram.waitFor([
- chakram
- .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
- .then(function (response) {
- expect(response).to.have.status(404);
- }),
- chakram
- .get('/domains/' + domain + '/rrsets/.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- }),
- ]);
- });
- itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
- });
- context("with a pre-existing RRset", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'c.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'delete-test', 'ttl': 50, 'type': 'A', 'records': ['127.1.2.3']},
- ]
- );
- return expect(response).to.have.status(201);
- });
- describe("can delete an RRset", function () {
- before(function () {
- var response = chakram.delete('/domains/' + domain + '/rrsets/delete-test.../A/');
- return expect(response).to.have.status(204);
- });
- itPropagatesToTheApi([
- {subname: 'delete-test', domain: domain, type: 'A', records: []},
- ]);
- itShowsUpInPdnsAs('delete-test', domain, 'A', []);
- });
- describe("cannot bulk-post existing or duplicate RRsets", function () {
- var response;
- before(function () {
- response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- ]
- );
- expect(response).to.have.status(400);
- return chakram.wait();
- });
- it("gives the right response", function () {
- expect(response).to.have.json([
- { '__all__': [ 'R rset with this Domain, Subname and Type already exists.' ] },
- { '__all__': [ 'RRset repeated with same subname and type.' ] },
- ]);
- return chakram.wait();
- });
- it("does not touch records in the API", function () {
- return chakram
- .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- });
- });
- itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"foo"'], 50);
- });
- describe("cannot delete RRsets via bulk-post", function () {
- var response;
- before(function () {
- response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'c.2', 'ttl': 40, 'type': 'TXT', 'records': []},
- ]
- );
- return expect(response).to.have.status(400);
- });
- it("gives the right response", function () {
- return expect(response).to.have.json([
- { '__all__': [ 'R rset with this Domain, Subname and Type already exists.' ] },
- ]);
- });
- });
- });
- describe("cannot bulk-post with invalid input", function () {
- it("gives the right response for invalid type", function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
- );
- return expect(response).to.have.status(422);
- });
- it("gives the right response for invalid records", function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
- );
- return expect(response).to.have.status(422);
- });
- });
- });
- describe('PUT rrsets/ with fresh domain', function () {
- var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
- before(function () {
- return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
- });
- describe("can overwrite a single existing RRset using PUT", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
- ).then(function () {
- return chakram.put(
- '/domains/' + domain + '/rrsets/single.../AAAA/',
- { 'records': ['fefe::bade'], 'ttl': 31 }
- );
- });
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrset);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
- ]);
- itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
- });
- describe("can bulk-put an AAAA and an MX record", function () {
- before(function () {
- var response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [
- { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
- { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
- ]
- );
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrsets);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
- {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
- ]);
- itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
- itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
- });
- describe("cannot bulk-put with missing or invalid fields", function () {
- before(function () {
- // Set an RRset that we'll try to overwrite
- var response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
- );
- expect(response).to.have.status(200);
- var response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
- {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
- {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
- {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
- ]
- );
- expect(response).to.have.status(400);
- expect(response).to.have.json([
- { type: [ 'This field is required.' ] },
- { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
- {},
- { ttl: [ 'This field is required.' ] },
- { records: [ 'This field is required.' ] },
- ]);
- return chakram.wait();
- });
- it("does not propagate partially to the API", function () {
- return chakram.waitFor([
- chakram
- .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
- .then(function (response) {
- expect(response).to.have.status(404);
- }),
- chakram
- .get('/domains/' + domain + '/rrsets/.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- }),
- ]);
- });
- itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
- });
- context("with a pre-existing RRset", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
- ]
- );
- expect(response).to.have.status(201);
- return chakram.wait();
- });
- describe("can bulk-put existing RRsets", function () {
- var response;
- before(function () {
- response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- ]
- );
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrsets);
- return chakram.wait();
- });
- it("does modify records in the API", function () {
- return chakram
- .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 40);
- expect(response.body.records).to.have.members(['"bar"']);
- });
- });
- itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
- });
- describe("cannot bulk-put duplicate RRsets", function () {
- var response;
- before(function () {
- response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
- ]
- );
- return expect(response).to.have.status(400);
- });
- it("gives the right response", function () {
- return expect(response).to.have.json([
- { },
- { '__all__': [ 'RRset repeated with same subname and type.' ] },
- ]);
- });
- it("does not touch records in the API", function () {
- return chakram
- .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- });
- });
- itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
- });
- describe("can delete RRsets via bulk-put", function () {
- var response;
- before(function () {
- response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'c.2', 'ttl': 40, 'type': 'A', 'records': []},
- ]
- );
- return expect(response).to.have.status(200);
- });
- it("gives the right response", function () {
- var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
- return expect(response).to.have.status(404);
- });
- });
- });
- describe("cannot bulk-put with invalid input", function () {
- it("gives the right response for invalid type", function () {
- var response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
- );
- return expect(response).to.have.status(422);
- });
- it("gives the right response for invalid records", function () {
- var response = chakram.put(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
- );
- return expect(response).to.have.status(422);
- });
- });
- });
- describe('PATCH rrsets/ with fresh domain', function () {
- var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
- before(function () {
- return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
- });
- describe("can modify a single existing RRset using PATCH", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
- ).then(function () {
- return chakram.patch(
- '/domains/' + domain + '/rrsets/single.../AAAA/',
- { 'records': ['fefe::bade'], 'ttl': 31 }
- );
- });
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrset);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
- ]);
- itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
- });
- describe("can bulk-patch an AAAA and an MX record", function () {
- before(function () {
- var response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
- { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
- ]
- );
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrsets);
- return chakram.wait();
- });
- itPropagatesToTheApi([
- {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
- {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
- ]);
- itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
- itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
- });
- describe("cannot bulk-patch with missing or invalid fields", function () {
- before(function () {
- // Set an RRset that we'll try to overwrite
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
- );
- expect(response).to.have.status(201);
- var response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
- {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
- {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
- {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
- ]
- );
- expect(response).to.have.status(400);
- expect(response).to.have.json([
- { type: [ 'This field is required.' ] },
- { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
- {},
- {},
- {},
- ]);
- return chakram.wait();
- });
- it("does not propagate partially to the API", function () {
- return chakram.waitFor([
- chakram
- .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
- .then(function (response) {
- expect(response).to.have.status(404);
- }),
- chakram
- .get('/domains/' + domain + '/rrsets/.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- }),
- ]);
- });
- itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
- });
- context("with a pre-existing RRset", function () {
- before(function () {
- var response = chakram.post(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.1', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'a.2', 'ttl': 50, 'type': 'A', 'records': ['4.3.2.1']},
- {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'b.2', 'ttl': 50, 'type': 'A', 'records': ['5.4.3.2']},
- {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
- {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
- ]
- );
- return expect(response).to.have.status(201);
- });
- describe("can bulk-patch existing RRsets", function () {
- var response;
- before(function () {
- response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.1', 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- ]
- );
- expect(response).to.have.status(200);
- expect(response).to.have.schema(schemas.rrsets);
- return chakram.wait();
- });
- it("does modify records in the API", function () {
- return chakram.waitFor([
- chakram
- .get('/domains/' + domain + '/rrsets/a.1.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"bar"']);
- }),
- chakram
- .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 40);
- expect(response.body.records).to.have.members(['"bar"']);
- }),
- ]);
- });
- itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
- });
- describe("cannot bulk-patch duplicate RRsets", function () {
- var response;
- before(function () {
- response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
- ]
- );
- return expect(response).to.have.status(400);
- });
- it("gives the right response", function () {
- return expect(response).to.have.json([
- {},
- { '__all__': [ 'RRset repeated with same subname and type.' ] },
- ]);
- });
- it("does not touch records in the API", function () {
- return chakram
- .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
- .then(function (response) {
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 50);
- expect(response.body.records).to.have.members(['"foo"']);
- });
- });
- itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
- });
- describe("can delete RRsets via bulk-patch", function () {
- var response;
- before(function () {
- response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'c.2', 'type': 'A', 'records': []},
- ]
- );
- return expect(response).to.have.status(200);
- });
- it("gives the right response", function () {
- var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
- return expect(response).to.have.status(404);
- });
- });
- describe("accepts missing fields for no-op requests via bulk-patch", function () {
- var response;
- before(function () {
- response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'a.2', 'type': 'A', 'records': ['6.6.6.6']}, // existing RRset; TTL not needed
- {'subname': 'b.2', 'type': 'A', 'ttl': 40}, // existing RRset; records not needed
- {'subname': 'x.2', 'type': 'A', 'records': []}, // non-existent, no-op
- {'subname': 'x.2', 'type': 'AAAA'}, // non-existent, no-op
- {'subname': 'x.2', 'type': 'TXT', 'ttl': 32}, // non-existent, no-op
- ]
- );
- return expect(response).to.have.status(200);
- });
- it("gives the right response", function () {
- var response = chakram.get('/domains/' + domain + '/rrsets/b.2.../A/');
- expect(response).to.have.status(200);
- expect(response).to.have.json('ttl', 40);
- return chakram.wait();
- });
- });
- describe("catches invalid type for no-op request via bulk-patch", function () {
- it("gives the right response", function () {
- return chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [
- {'subname': 'x.2', 'type': 'AAA'}, // non-existent, no-op, but invalid type
- ]
- ).then(function (respObj) {
- expect(respObj).to.have.status(422);
- expect(respObj.body.detail).to.match(/IN AAA: unknown type given$/);
- return chakram.wait();
- });
- });
- });
- });
- describe("cannot bulk-patch with invalid input", function () {
- it("gives the right response for invalid type", function () {
- var response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
- );
- return expect(response).to.have.status(422);
- });
- it("gives the right response for invalid records", function () {
- var response = chakram.patch(
- '/domains/' + domain + '/rrsets/',
- [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
- );
- return expect(response).to.have.status(422);
- });
- });
- });
- describe("tokens/ endpoint", function () {
- var tokenId;
- var tokenValue;
- function createTokenWithName () {
- var tokenname = "e2e-token-" + require("uuid").v4();
- return chakram.post('/tokens/', { name: tokenname }).then(function (response) {
- expect(response).to.have.status(201);
- expect(response).to.have.json('name', tokenname);
- tokenId = response.body['id'];
- });
- }
- function createToken () {
- return chakram.post('/tokens/').then(function (response) {
- expect(response).to.have.status(201);
- tokenId = response.body['id'];
- tokenValue = response.body['value'];
- });
- }
- it("can create tokens", createToken);
- it("can create tokens with name", createTokenWithName)
- describe("with tokens", function () {
- before(createToken)
- it("a list of tokens can be retrieved", function () {
- var response = chakram.get('/tokens/');
- return expect(response).to.have.schema(schemas.tokens);
- });
- describe("can delete token", function () {
- before( function () {
- var response = chakram.delete('/tokens/' + tokenId + '/');
- return expect(response).to.have.status(204);
- });
- it("deactivates the token", function () {
- return expect(chakram.get('/tokens/', {
- headers: {'Authorization': 'Token ' + tokenValue }
- })).to.have.status(401);
- });
- });
- it("deleting nonexistent tokens yields 204", function () {
- var response = chakram.delete('/tokens/wedonthavethisid/');
- return expect(response).to.have.status(204);
- });
- });
- })
- });
- });
- });
|