12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- 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 login", function () {
- var email, password, token;
- 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", 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;
- });
- });
- 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("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);
- });
- });
- })
- });
- });
- });
|