api_spec.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. var chakram = require("./../setup.js").chakram;
  2. var expect = chakram.expect;
  3. var itPropagatesToTheApi = require("./../setup.js").itPropagatesToTheApi;
  4. var itShowsUpInPdnsAs = require("./../setup.js").itShowsUpInPdnsAs;
  5. var schemas = require("./../schemas.js");
  6. describe("API", function () {
  7. before(function () {
  8. chakram.setRequestDefaults({
  9. headers: {
  10. 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
  11. },
  12. followRedirect: false,
  13. baseUrl: 'https://www/api/v1',
  14. })
  15. });
  16. it("provides an index page", function () {
  17. var response = chakram.get('/');
  18. return expect(response).to.have.status(200);
  19. });
  20. describe("user registration", function () {
  21. it("returns a user object", function () {
  22. var email, password, token;
  23. email = require("uuid").v4() + '@e2etest.local';
  24. password = require("uuid").v4();
  25. var response = chakram.post('/auth/users/create/', {
  26. "email": email,
  27. "password": password,
  28. });
  29. return expect(response).to.have.status(201);
  30. });
  31. it("locks new users that look suspicious");
  32. });
  33. describe("user login", function () {
  34. var email, password, token;
  35. before(function () {
  36. // register a user that we can work with
  37. email = require("uuid").v4() + '@e2etest.local';
  38. password = require("uuid").v4();
  39. var response = chakram.post('/auth/users/create/', {
  40. "email": email,
  41. "password": password,
  42. });
  43. return expect(response).to.have.status(201);
  44. });
  45. it("returns a token", function () {
  46. return chakram.post('/auth/token/create/', {
  47. "email": email,
  48. "password": password,
  49. }).then(function (loginResponse) {
  50. expect(loginResponse.body.auth_token).to.match(/^[a-z0-9]{40}$/);
  51. token = loginResponse.body.auth_token;
  52. });
  53. });
  54. });
  55. var email = require("uuid").v4() + '@e2etest.local';
  56. describe("with user account [" + email + "]", function () {
  57. var apiHomeSchema = {
  58. properties: {
  59. domains: {type: "string"},
  60. logout: {type: "string"},
  61. user: {type: "string"},
  62. },
  63. required: ["domains", "logout", "user"]
  64. };
  65. var password, token;
  66. before(function () {
  67. chakram.setRequestSettings({
  68. headers: {
  69. 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
  70. },
  71. followRedirect: false,
  72. baseUrl: 'https://www/api/v1',
  73. });
  74. // register a user that we can login and work with
  75. password = require("uuid").v4();
  76. return chakram.post('/auth/users/create/', {
  77. "email": email,
  78. "password": password,
  79. }).then(function () {
  80. return chakram.post('/auth/token/create/', {
  81. "email": email,
  82. "password": password,
  83. }).then(function (loginResponse) {
  84. expect(loginResponse.body.auth_token).to.match(/^[a-z0-9]{40}$/);
  85. token = loginResponse.body.auth_token;
  86. chakram.setRequestHeader('Authorization', 'Token ' + token);
  87. });
  88. });
  89. });
  90. describe("(logged in)", function () {
  91. describe("api 'homepage'", function () {
  92. var response;
  93. before(function () {
  94. response = chakram.get('/');
  95. });
  96. it('has status 200', function () {
  97. return expect(response).to.have.status(200);
  98. });
  99. it('looks according to the schema', function () {
  100. return expect(response).to.have.schema(apiHomeSchema);
  101. });
  102. });
  103. describe("on domains/ endpoint", function () {
  104. var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
  105. before(function () {
  106. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  107. });
  108. it("can register a domain name", function () {
  109. var response = chakram.get('/domains/' + domain + '/');
  110. expect(response).to.have.status(200);
  111. expect(response).to.have.schema(schemas.domain);
  112. return chakram.wait();
  113. });
  114. describe("on rrsets/ endpoint", function () {
  115. it("can retrieve RRsets", function () {
  116. var response = chakram.get('/domains/' + domain + '/rrsets/');
  117. expect(response).to.have.status(200);
  118. expect(response).to.have.schema(schemas.rrsets);
  119. response = chakram.get('/domains/' + domain + '/rrsets/.../NS/');
  120. expect(response).to.have.status(200);
  121. expect(response).to.have.schema(schemas.rrset);
  122. return chakram.wait();
  123. });
  124. });
  125. });
  126. describe('POST rrsets/ with fresh domain', function () {
  127. var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
  128. before(function () {
  129. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  130. });
  131. describe("can set an A RRset", function () {
  132. before(function () {
  133. var response = chakram.post(
  134. '/domains/' + domain + '/rrsets/',
  135. {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
  136. );
  137. expect(response).to.have.status(201);
  138. expect(response).to.have.schema(schemas.rrset);
  139. expect(response).to.have.json('ttl', 60);
  140. expect(response).to.have.json('records', ['127.0.0.1']);
  141. return chakram.wait();
  142. });
  143. itPropagatesToTheApi([
  144. {subname: '', domain: domain, type: 'A', ttl: 60, records: ['127.0.0.1']},
  145. ]);
  146. itShowsUpInPdnsAs('', domain, 'A', ['127.0.0.1'], 60);
  147. });
  148. describe("can set a wildcard AAAA RRset with multiple records", function () {
  149. before(function () {
  150. return chakram.post(
  151. '/domains/' + domain + '/rrsets/',
  152. {'subname': '*.foobar', 'type': 'AAAA', 'records': ['::1', 'bade::affe'], 'ttl': 60}
  153. );
  154. });
  155. itPropagatesToTheApi([
  156. {subname: '*.foobar', domain: domain, type: 'AAAA', ttl: 60, records: ['::1', 'bade::affe']},
  157. {subname: '*.foobar', domain: domain, type: 'AAAA', records: ['bade::affe', '::1']},
  158. ]);
  159. itShowsUpInPdnsAs('test.foobar', domain, 'AAAA', ['::1', 'bade::affe'], 60);
  160. });
  161. describe("can bulk-post an AAAA and an MX record", function () {
  162. before(function () {
  163. var response = chakram.post(
  164. '/domains/' + domain + '/rrsets/',
  165. [
  166. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  167. { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  168. ]
  169. );
  170. expect(response).to.have.status(201);
  171. expect(response).to.have.schema(schemas.rrsets);
  172. return chakram.wait();
  173. });
  174. itPropagatesToTheApi([
  175. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  176. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  177. ]);
  178. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  179. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  180. });
  181. describe("cannot bulk-post with missing or invalid fields", function () {
  182. before(function () {
  183. // Set an RRset that we'll try to overwrite
  184. var response = chakram.post(
  185. '/domains/' + domain + '/rrsets/',
  186. [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
  187. );
  188. expect(response).to.have.status(201);
  189. var response = chakram.post(
  190. '/domains/' + domain + '/rrsets/',
  191. [
  192. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  193. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  194. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  195. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  196. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  197. {'subname': 'd.1', 'ttl': 50, 'type': 'SOA', 'records': ['ns1.desec.io. peter.desec.io. 2018034419 10800 3600 604800 60']},
  198. {'subname': 'd.1', 'ttl': 50, 'type': 'OPT', 'records': ['9999']},
  199. ]
  200. );
  201. expect(response).to.have.status(400);
  202. expect(response).to.have.json([
  203. { type: [ 'This field is required.' ] },
  204. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  205. {},
  206. { ttl: [ 'This field is required.' ] },
  207. { records: [ 'This field is required.' ] },
  208. { type: [ 'You cannot tinker with the SOA RRset.' ] },
  209. { type: [ 'You cannot tinker with the OPT RRset.' ] },
  210. ]);
  211. return chakram.wait();
  212. });
  213. it("does not propagate partially to the API", function () {
  214. return chakram.waitFor([
  215. chakram
  216. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  217. .then(function (response) {
  218. expect(response).to.have.status(404);
  219. }),
  220. chakram
  221. .get('/domains/' + domain + '/rrsets/.../TXT/')
  222. .then(function (response) {
  223. expect(response).to.have.status(200);
  224. expect(response).to.have.json('ttl', 50);
  225. expect(response.body.records).to.have.members(['"foo"']);
  226. }),
  227. ]);
  228. });
  229. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  230. });
  231. context("with a pre-existing RRset", function () {
  232. before(function () {
  233. var response = chakram.post(
  234. '/domains/' + domain + '/rrsets/',
  235. [
  236. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  237. {'subname': 'c.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  238. {'subname': 'delete-test', 'ttl': 50, 'type': 'A', 'records': ['127.1.2.3']},
  239. ]
  240. );
  241. return expect(response).to.have.status(201);
  242. });
  243. describe("can delete an RRset", function () {
  244. before(function () {
  245. var response = chakram.delete('/domains/' + domain + '/rrsets/delete-test.../A/');
  246. return expect(response).to.have.status(204);
  247. });
  248. itPropagatesToTheApi([
  249. {subname: 'delete-test', domain: domain, type: 'A', records: []},
  250. ]);
  251. itShowsUpInPdnsAs('delete-test', domain, 'A', []);
  252. });
  253. describe("cannot bulk-post existing or duplicate RRsets", function () {
  254. var response;
  255. before(function () {
  256. response = chakram.post(
  257. '/domains/' + domain + '/rrsets/',
  258. [
  259. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  260. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  261. ]
  262. );
  263. expect(response).to.have.status(400);
  264. return chakram.wait();
  265. });
  266. it("gives the right response", function () {
  267. expect(response).to.have.json([
  268. { '__all__': [ 'R rset with this Domain, Subname and Type already exists.' ] },
  269. { '__all__': [ 'RRset repeated with same subname and type.' ] },
  270. ]);
  271. return chakram.wait();
  272. });
  273. it("does not touch records in the API", function () {
  274. return chakram
  275. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  276. .then(function (response) {
  277. expect(response).to.have.status(200);
  278. expect(response).to.have.json('ttl', 50);
  279. expect(response.body.records).to.have.members(['"foo"']);
  280. });
  281. });
  282. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"foo"'], 50);
  283. });
  284. describe("cannot delete RRsets via bulk-post", function () {
  285. var response;
  286. before(function () {
  287. response = chakram.post(
  288. '/domains/' + domain + '/rrsets/',
  289. [
  290. {'subname': 'c.2', 'ttl': 40, 'type': 'TXT', 'records': []},
  291. ]
  292. );
  293. return expect(response).to.have.status(400);
  294. });
  295. it("gives the right response", function () {
  296. return expect(response).to.have.json([
  297. { '__all__': [ 'R rset with this Domain, Subname and Type already exists.' ] },
  298. ]);
  299. });
  300. });
  301. });
  302. describe("cannot bulk-post with invalid input", function () {
  303. it("gives the right response for invalid type", function () {
  304. var response = chakram.post(
  305. '/domains/' + domain + '/rrsets/',
  306. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  307. );
  308. return expect(response).to.have.status(422);
  309. });
  310. it("gives the right response for invalid records", function () {
  311. var response = chakram.post(
  312. '/domains/' + domain + '/rrsets/',
  313. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  314. );
  315. return expect(response).to.have.status(422);
  316. });
  317. });
  318. });
  319. describe('PUT rrsets/ with fresh domain', function () {
  320. var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
  321. before(function () {
  322. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  323. });
  324. describe("can overwrite a single existing RRset using PUT", function () {
  325. before(function () {
  326. var response = chakram.post(
  327. '/domains/' + domain + '/rrsets/',
  328. { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
  329. ).then(function () {
  330. return chakram.put(
  331. '/domains/' + domain + '/rrsets/single.../AAAA/',
  332. { 'records': ['fefe::bade'], 'ttl': 31 }
  333. );
  334. });
  335. expect(response).to.have.status(200);
  336. expect(response).to.have.schema(schemas.rrset);
  337. return chakram.wait();
  338. });
  339. itPropagatesToTheApi([
  340. {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
  341. ]);
  342. itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
  343. });
  344. describe("can bulk-put an AAAA and an MX record", function () {
  345. before(function () {
  346. var response = chakram.put(
  347. '/domains/' + domain + '/rrsets/',
  348. [
  349. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  350. { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  351. ]
  352. );
  353. expect(response).to.have.status(200);
  354. expect(response).to.have.schema(schemas.rrsets);
  355. return chakram.wait();
  356. });
  357. itPropagatesToTheApi([
  358. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  359. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  360. ]);
  361. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  362. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  363. });
  364. describe("cannot bulk-put with missing or invalid fields", function () {
  365. before(function () {
  366. // Set an RRset that we'll try to overwrite
  367. var response = chakram.put(
  368. '/domains/' + domain + '/rrsets/',
  369. [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
  370. );
  371. expect(response).to.have.status(200);
  372. var response = chakram.put(
  373. '/domains/' + domain + '/rrsets/',
  374. [
  375. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  376. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  377. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  378. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  379. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  380. ]
  381. );
  382. expect(response).to.have.status(400);
  383. expect(response).to.have.json([
  384. { type: [ 'This field is required.' ] },
  385. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  386. {},
  387. { ttl: [ 'This field is required.' ] },
  388. { records: [ 'This field is required.' ] },
  389. ]);
  390. return chakram.wait();
  391. });
  392. it("does not propagate partially to the API", function () {
  393. return chakram.waitFor([
  394. chakram
  395. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  396. .then(function (response) {
  397. expect(response).to.have.status(404);
  398. }),
  399. chakram
  400. .get('/domains/' + domain + '/rrsets/.../TXT/')
  401. .then(function (response) {
  402. expect(response).to.have.status(200);
  403. expect(response).to.have.json('ttl', 50);
  404. expect(response.body.records).to.have.members(['"foo"']);
  405. }),
  406. ]);
  407. });
  408. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  409. });
  410. context("with a pre-existing RRset", function () {
  411. before(function () {
  412. var response = chakram.post(
  413. '/domains/' + domain + '/rrsets/',
  414. [
  415. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  416. {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  417. {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
  418. ]
  419. );
  420. expect(response).to.have.status(201);
  421. return chakram.wait();
  422. });
  423. describe("can bulk-put existing RRsets", function () {
  424. var response;
  425. before(function () {
  426. response = chakram.put(
  427. '/domains/' + domain + '/rrsets/',
  428. [
  429. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  430. ]
  431. );
  432. expect(response).to.have.status(200);
  433. expect(response).to.have.schema(schemas.rrsets);
  434. return chakram.wait();
  435. });
  436. it("does modify records in the API", function () {
  437. return chakram
  438. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  439. .then(function (response) {
  440. expect(response).to.have.status(200);
  441. expect(response).to.have.json('ttl', 40);
  442. expect(response.body.records).to.have.members(['"bar"']);
  443. });
  444. });
  445. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
  446. });
  447. describe("cannot bulk-put duplicate RRsets", function () {
  448. var response;
  449. before(function () {
  450. response = chakram.put(
  451. '/domains/' + domain + '/rrsets/',
  452. [
  453. {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
  454. {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
  455. ]
  456. );
  457. return expect(response).to.have.status(400);
  458. });
  459. it("gives the right response", function () {
  460. return expect(response).to.have.json([
  461. { },
  462. { '__all__': [ 'RRset repeated with same subname and type.' ] },
  463. ]);
  464. });
  465. it("does not touch records in the API", function () {
  466. return chakram
  467. .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
  468. .then(function (response) {
  469. expect(response).to.have.status(200);
  470. expect(response).to.have.json('ttl', 50);
  471. expect(response.body.records).to.have.members(['"foo"']);
  472. });
  473. });
  474. itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
  475. });
  476. describe("can delete RRsets via bulk-put", function () {
  477. var response;
  478. before(function () {
  479. response = chakram.put(
  480. '/domains/' + domain + '/rrsets/',
  481. [
  482. {'subname': 'c.2', 'ttl': 40, 'type': 'A', 'records': []},
  483. ]
  484. );
  485. return expect(response).to.have.status(200);
  486. });
  487. it("gives the right response", function () {
  488. var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
  489. return expect(response).to.have.status(404);
  490. });
  491. });
  492. });
  493. describe("cannot bulk-put with invalid input", function () {
  494. it("gives the right response for invalid type", function () {
  495. var response = chakram.put(
  496. '/domains/' + domain + '/rrsets/',
  497. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  498. );
  499. return expect(response).to.have.status(422);
  500. });
  501. it("gives the right response for invalid records", function () {
  502. var response = chakram.put(
  503. '/domains/' + domain + '/rrsets/',
  504. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  505. );
  506. return expect(response).to.have.status(422);
  507. });
  508. });
  509. });
  510. describe('PATCH rrsets/ with fresh domain', function () {
  511. var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
  512. before(function () {
  513. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  514. });
  515. describe("can modify a single existing RRset using PATCH", function () {
  516. before(function () {
  517. var response = chakram.post(
  518. '/domains/' + domain + '/rrsets/',
  519. { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
  520. ).then(function () {
  521. return chakram.patch(
  522. '/domains/' + domain + '/rrsets/single.../AAAA/',
  523. { 'records': ['fefe::bade'], 'ttl': 31 }
  524. );
  525. });
  526. expect(response).to.have.status(200);
  527. expect(response).to.have.schema(schemas.rrset);
  528. return chakram.wait();
  529. });
  530. itPropagatesToTheApi([
  531. {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
  532. ]);
  533. itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
  534. });
  535. describe("can bulk-patch an AAAA and an MX record", function () {
  536. before(function () {
  537. var response = chakram.patch(
  538. '/domains/' + domain + '/rrsets/',
  539. [
  540. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  541. { /* implied: 'subname': '', */ 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  542. ]
  543. );
  544. expect(response).to.have.status(200);
  545. expect(response).to.have.schema(schemas.rrsets);
  546. return chakram.wait();
  547. });
  548. itPropagatesToTheApi([
  549. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  550. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  551. ]);
  552. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  553. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  554. });
  555. describe("cannot bulk-patch with missing or invalid fields", function () {
  556. before(function () {
  557. // Set an RRset that we'll try to overwrite
  558. var response = chakram.post(
  559. '/domains/' + domain + '/rrsets/',
  560. [{'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}]
  561. );
  562. expect(response).to.have.status(201);
  563. var response = chakram.patch(
  564. '/domains/' + domain + '/rrsets/',
  565. [
  566. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  567. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  568. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  569. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  570. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  571. ]
  572. );
  573. expect(response).to.have.status(400);
  574. expect(response).to.have.json([
  575. { type: [ 'This field is required.' ] },
  576. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  577. {},
  578. {},
  579. {},
  580. ]);
  581. return chakram.wait();
  582. });
  583. it("does not propagate partially to the API", function () {
  584. return chakram.waitFor([
  585. chakram
  586. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  587. .then(function (response) {
  588. expect(response).to.have.status(404);
  589. }),
  590. chakram
  591. .get('/domains/' + domain + '/rrsets/.../TXT/')
  592. .then(function (response) {
  593. expect(response).to.have.status(200);
  594. expect(response).to.have.json('ttl', 50);
  595. expect(response.body.records).to.have.members(['"foo"']);
  596. }),
  597. ]);
  598. });
  599. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  600. });
  601. context("with a pre-existing RRset", function () {
  602. before(function () {
  603. var response = chakram.post(
  604. '/domains/' + domain + '/rrsets/',
  605. [
  606. {'subname': 'a.1', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  607. {'subname': 'a.2', 'ttl': 50, 'type': 'A', 'records': ['4.3.2.1']},
  608. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  609. {'subname': 'b.2', 'ttl': 50, 'type': 'A', 'records': ['5.4.3.2']},
  610. {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  611. {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
  612. ]
  613. );
  614. return expect(response).to.have.status(201);
  615. });
  616. describe("can bulk-patch existing RRsets", function () {
  617. var response;
  618. before(function () {
  619. response = chakram.patch(
  620. '/domains/' + domain + '/rrsets/',
  621. [
  622. {'subname': 'a.1', 'type': 'TXT', 'records': ['"bar"']},
  623. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  624. ]
  625. );
  626. expect(response).to.have.status(200);
  627. expect(response).to.have.schema(schemas.rrsets);
  628. return chakram.wait();
  629. });
  630. it("does modify records in the API", function () {
  631. return chakram.waitFor([
  632. chakram
  633. .get('/domains/' + domain + '/rrsets/a.1.../TXT/')
  634. .then(function (response) {
  635. expect(response).to.have.status(200);
  636. expect(response).to.have.json('ttl', 50);
  637. expect(response.body.records).to.have.members(['"bar"']);
  638. }),
  639. chakram
  640. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  641. .then(function (response) {
  642. expect(response).to.have.status(200);
  643. expect(response).to.have.json('ttl', 40);
  644. expect(response.body.records).to.have.members(['"bar"']);
  645. }),
  646. ]);
  647. });
  648. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
  649. });
  650. describe("cannot bulk-patch duplicate RRsets", function () {
  651. var response;
  652. before(function () {
  653. response = chakram.patch(
  654. '/domains/' + domain + '/rrsets/',
  655. [
  656. {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  657. {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  658. ]
  659. );
  660. return expect(response).to.have.status(400);
  661. });
  662. it("gives the right response", function () {
  663. return expect(response).to.have.json([
  664. {},
  665. { '__all__': [ 'RRset repeated with same subname and type.' ] },
  666. ]);
  667. });
  668. it("does not touch records in the API", function () {
  669. return chakram
  670. .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
  671. .then(function (response) {
  672. expect(response).to.have.status(200);
  673. expect(response).to.have.json('ttl', 50);
  674. expect(response.body.records).to.have.members(['"foo"']);
  675. });
  676. });
  677. itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
  678. });
  679. describe("can delete RRsets via bulk-patch", function () {
  680. var response;
  681. before(function () {
  682. response = chakram.patch(
  683. '/domains/' + domain + '/rrsets/',
  684. [
  685. {'subname': 'c.2', 'type': 'A', 'records': []},
  686. ]
  687. );
  688. return expect(response).to.have.status(200);
  689. });
  690. it("gives the right response", function () {
  691. var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
  692. return expect(response).to.have.status(404);
  693. });
  694. });
  695. describe("accepts missing fields for no-op requests via bulk-patch", function () {
  696. var response;
  697. before(function () {
  698. response = chakram.patch(
  699. '/domains/' + domain + '/rrsets/',
  700. [
  701. {'subname': 'a.2', 'type': 'A', 'records': ['6.6.6.6']}, // existing RRset; TTL not needed
  702. {'subname': 'b.2', 'type': 'A', 'ttl': 40}, // existing RRset; records not needed
  703. {'subname': 'x.2', 'type': 'A', 'records': []}, // non-existent, no-op
  704. {'subname': 'x.2', 'type': 'AAAA'}, // non-existent, no-op
  705. {'subname': 'x.2', 'type': 'TXT', 'ttl': 32}, // non-existent, no-op
  706. ]
  707. );
  708. return expect(response).to.have.status(200);
  709. });
  710. it("gives the right response", function () {
  711. var response = chakram.get('/domains/' + domain + '/rrsets/b.2.../A/');
  712. expect(response).to.have.status(200);
  713. expect(response).to.have.json('ttl', 40);
  714. return chakram.wait();
  715. });
  716. });
  717. describe("catches invalid type for no-op request via bulk-patch", function () {
  718. it("gives the right response", function () {
  719. return chakram.patch(
  720. '/domains/' + domain + '/rrsets/',
  721. [
  722. {'subname': 'x.2', 'type': 'AAA'}, // non-existent, no-op, but invalid type
  723. ]
  724. ).then(function (respObj) {
  725. expect(respObj).to.have.status(422);
  726. expect(respObj.body.detail).to.match(/IN AAA: unknown type given$/);
  727. return chakram.wait();
  728. });
  729. });
  730. });
  731. });
  732. describe("cannot bulk-patch with invalid input", function () {
  733. it("gives the right response for invalid type", function () {
  734. var response = chakram.patch(
  735. '/domains/' + domain + '/rrsets/',
  736. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  737. );
  738. return expect(response).to.have.status(422);
  739. });
  740. it("gives the right response for invalid records", function () {
  741. var response = chakram.patch(
  742. '/domains/' + domain + '/rrsets/',
  743. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  744. );
  745. return expect(response).to.have.status(422);
  746. });
  747. });
  748. });
  749. });
  750. });
  751. });