api_spec.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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 Versioning", 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',
  14. })
  15. });
  16. [
  17. 'v1',
  18. 'v2',
  19. ].forEach(function (version) {
  20. it("maintains the requested version " + version, function() {
  21. chakram.get('/' + version + '/').then(function (response) {
  22. expect(response).to.have.schema(schemas.rootNoLogin);
  23. let regex = new RegExp('http://[^/]+/api/' + version + '/auth/users/', 'g')
  24. expect(response.body.login).to.match(regex);
  25. return chakram.wait();
  26. });
  27. });
  28. })
  29. });
  30. describe("API v1", function () {
  31. this.timeout(3000);
  32. let publicSuffix = 'dedyn.io'; // TODO replace with env variable
  33. before(function () {
  34. chakram.setRequestDefaults({
  35. headers: {
  36. 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
  37. },
  38. followRedirect: false,
  39. baseUrl: 'https://www/api/v1',
  40. })
  41. let credentials = {"email":"admin@e2etest.local", "password": "password"};
  42. return chakram.post('/auth/users/', credentials).then(function() {
  43. chakram.post('/auth/token/login/', credentials).then(function (response) {
  44. let config = {headers: {'Authorization': 'Token ' + response.body.auth_token}}
  45. chakram.post('/domains/', {name: publicSuffix}, config)
  46. // TODO verify behavior for non-existent local public suffixes
  47. });
  48. });
  49. });
  50. it("provides an index page", function () {
  51. chakram.get('/').then(function (response) {
  52. expect(response).to.have.schema(schemas.rootNoLogin);
  53. expect(response.body.login).to.match(/http:\/\/[^\/]+\/api\/v1\/auth\/users\//);
  54. return chakram.wait();
  55. });
  56. });
  57. describe("user registration", function () {
  58. it("returns a user object", function () {
  59. var email, password, token;
  60. email = require("uuid").v4() + '@e2etest.local';
  61. password = require("uuid").v4();
  62. var response = chakram.post('/auth/users/', {
  63. "email": email,
  64. "password": password,
  65. });
  66. return expect(response).to.have.status(201);
  67. });
  68. it("locks new users that look suspicious");
  69. });
  70. describe("user account", function () {
  71. var email, password;
  72. before(function () {
  73. // register a user that we can work with
  74. email = require("uuid").v4() + '@e2etest.local';
  75. password = require("uuid").v4();
  76. var response = chakram.post('/auth/users/', {
  77. "email": email,
  78. "password": password,
  79. });
  80. return expect(response).to.have.status(201);
  81. });
  82. it("returns a token when logging in", function () {
  83. return chakram.post('/auth/token/login/', {
  84. "email": email,
  85. "password": password,
  86. }).then(function (loginResponse) {
  87. expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
  88. });
  89. });
  90. describe("auth/me/ endpoint", function () {
  91. var email2, password2, token2;
  92. before(function () {
  93. // register an independent user to screw around with
  94. email2 = require("uuid").v4() + '@e2etest.local';
  95. password2 = require("uuid").v4();
  96. return chakram.post('/auth/users/', {
  97. "email": email2,
  98. "password": password2,
  99. }).then(function () {
  100. return chakram.post('/auth/token/login/', {
  101. "email": email2,
  102. "password": password2,
  103. }).then(function (response) {
  104. token2 = response.body.auth_token
  105. });
  106. });
  107. });
  108. it("returns JSON of correct schema", function () {
  109. var response = chakram.get('/auth/me/', {
  110. headers: {'Authorization': 'Token ' + token2 }
  111. });
  112. expect(response).to.have.status(200);
  113. expect(response).to.have.schema(schemas.user);
  114. return chakram.wait();
  115. });
  116. it("allows changing email address", function () {
  117. let email3 = require("uuid").v4() + '@e2etest.local';
  118. return chakram.put('/auth/me/',
  119. {'email': email3},
  120. {headers: {'Authorization': 'Token ' + token2}}
  121. ).then(function (response) {
  122. expect(response).to.have.status(200);
  123. expect(response).to.have.schema(schemas.user);
  124. expect(response.body.email).to.equal(email3);
  125. });
  126. });
  127. });
  128. describe("token management (djoser)", function () {
  129. var token1, token2;
  130. function createTwoTokens() {
  131. return chakram.waitFor([
  132. chakram.post('/auth/token/login/', {
  133. "email": email,
  134. "password": password,
  135. }).then(function (loginResponse) {
  136. expect(loginResponse).to.have.status(201);
  137. expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
  138. token1 = loginResponse.body.auth_token;
  139. expect(token1).to.not.equal(token2);
  140. }),
  141. chakram.post('/auth/token/login/', {
  142. "email": email,
  143. "password": password,
  144. }).then(function (loginResponse) {
  145. expect(loginResponse).to.have.status(201);
  146. expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
  147. token2 = loginResponse.body.auth_token;
  148. expect(token2).to.not.equal(token1);
  149. })
  150. ]);
  151. }
  152. function deleteToken(token) {
  153. var response = chakram.post('/auth/token/logout/', null, {
  154. headers: {'Authorization': 'Token ' + token}
  155. });
  156. return expect(response).to.have.status(204);
  157. }
  158. it("can create additional tokens", createTwoTokens);
  159. describe("additional tokens", function () {
  160. before(createTwoTokens);
  161. it("can be used for login (1)", function () {
  162. return expect(chakram.get('/domains/', {
  163. headers: {'Authorization': 'Token ' + token1 }
  164. })).to.have.status(200);
  165. });
  166. it("can be used for login (2)", function () {
  167. return expect(chakram.get('/domains/', {
  168. headers: {'Authorization': 'Token ' + token2 }
  169. })).to.have.status(200);
  170. });
  171. describe("and one deleted", function () {
  172. before(function () {
  173. var response = chakram.post('/auth/token/logout/', undefined,
  174. { headers: {'Authorization': 'Token ' + token1 } }
  175. );
  176. return expect(response).to.have.status(204);
  177. });
  178. it("leaves the other untouched", function () {
  179. return expect(chakram.get('/domains/', {
  180. headers: {'Authorization': 'Token ' + token2 }
  181. })).to.have.status(200);
  182. });
  183. });
  184. });
  185. });
  186. });
  187. var email = require("uuid").v4() + '@e2etest.local';
  188. describe("with user account [" + email + "]", function () {
  189. var apiHomeSchema = {
  190. properties: {
  191. domains: {type: "string"},
  192. logout: {type: "string"},
  193. user: {type: "string"},
  194. },
  195. required: ["domains", "logout", "user"]
  196. };
  197. var password, token;
  198. before(function () {
  199. chakram.setRequestSettings({
  200. headers: {
  201. 'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
  202. },
  203. followRedirect: false,
  204. baseUrl: 'https://www/api/v1',
  205. });
  206. // register a user that we can login and work with
  207. password = require("uuid").v4();
  208. return chakram.post('/auth/users/', {
  209. "email": email,
  210. "password": password,
  211. }).then(function () {
  212. return chakram.post('/auth/token/login/', {
  213. "email": email,
  214. "password": password,
  215. }).then(function (loginResponse) {
  216. expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
  217. token = loginResponse.body.auth_token;
  218. chakram.setRequestHeader('Authorization', 'Token ' + token);
  219. });
  220. });
  221. });
  222. describe("(logged in)", function () {
  223. describe("api 'homepage'", function () {
  224. var response;
  225. before(function () {
  226. response = chakram.get('/');
  227. });
  228. it('has status 200', function () {
  229. return expect(response).to.have.status(200);
  230. });
  231. it('looks according to the schema', function () {
  232. return expect(response).to.have.schema(apiHomeSchema);
  233. });
  234. });
  235. describe("on domains/ endpoint", function () {
  236. var domain = 'e2etest-' + require("uuid").v4() + '.' + publicSuffix;
  237. before(function () {
  238. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  239. });
  240. it("can register a domain name", function () {
  241. var response = chakram.get('/domains/' + domain + '/');
  242. expect(response).to.have.status(200);
  243. expect(response).to.have.schema(schemas.domain);
  244. return chakram.wait();
  245. });
  246. itShowsUpInPdnsAs('', domain, 'NS', process.env.DESECSTACK_NS.split(/\s+/), process.env.DESECSTACK_NSLORD_DEFAULT_TTL);
  247. describe("on rrsets/ endpoint", function () {
  248. it("can retrieve RRsets", function () {
  249. var response = chakram.get('/domains/' + domain + '/rrsets/');
  250. expect(response).to.have.status(200);
  251. expect(response).to.have.schema(schemas.rrsets);
  252. response = chakram.get('/domains/' + domain + '/rrsets/.../NS/');
  253. expect(response).to.have.status(200);
  254. expect(response).to.have.schema(schemas.rrset);
  255. response = chakram.get('/domains/' + domain + '/rrsets/@/NS/');
  256. expect(response).to.have.status(200);
  257. expect(response).to.have.schema(schemas.rrset);
  258. return chakram.wait();
  259. });
  260. });
  261. });
  262. describe('POST rrsets/ with fresh domain', function () {
  263. var domain = 'e2etest-' + require("uuid").v4() + '.' + publicSuffix;
  264. before(function () {
  265. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  266. });
  267. describe("can set an A RRset", function () {
  268. before(function () {
  269. var response = chakram.post(
  270. '/domains/' + domain + '/rrsets/',
  271. {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
  272. );
  273. expect(response).to.have.status(201);
  274. expect(response).to.have.schema(schemas.rrset);
  275. expect(response).to.have.json('ttl', 60);
  276. expect(response).to.have.json('records', ['127.0.0.1']);
  277. return chakram.wait();
  278. });
  279. itPropagatesToTheApi([
  280. {subname: '', domain: domain, type: 'A', ttl: 60, records: ['127.0.0.1']},
  281. ]);
  282. itShowsUpInPdnsAs('', domain, 'A', ['127.0.0.1'], 60);
  283. });
  284. describe("cannot create RRsets of restricted or dead type", function () {
  285. var rrTypes = ['DNAME', 'ALIAS', 'SOA', 'RRSIG', 'DNSKEY', 'NSEC3PARAM', 'OPT'];
  286. for (var i = 0; i < rrTypes.length; i++) {
  287. var rrType = rrTypes[i];
  288. it(rrType, function () {
  289. return expect(chakram.post(
  290. '/domains/' + domain + '/rrsets/',
  291. {'subname': 'not-welcome', 'type': rrType, 'records': ['127.0.0.1'], 'ttl': 60}
  292. )).to.have.status(400);
  293. });
  294. }
  295. });
  296. it("cannot update RRSets for nonexistent domain name", function () {
  297. return expect(chakram.patch(
  298. '/domains/nonexistent.e2e.domain/rrsets/',
  299. {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
  300. )).to.have.status(404);
  301. });
  302. it("cannot create RRSets for nonexistent domain name", function () {
  303. return expect(chakram.post(
  304. '/domains/nonexistent.e2e.domain/rrsets/',
  305. {'subname': '', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
  306. )).to.have.status(404);
  307. });
  308. it("cannot set unicode RRsets", function () {
  309. return expect(chakram.post(
  310. '/domains/' + domain + '/rrsets/',
  311. {'subname': '想不出来', 'type': 'A', 'records': ['127.0.0.1'], 'ttl': 60}
  312. )).to.have.status(400);
  313. });
  314. describe("can set a wildcard AAAA RRset with multiple records", function () {
  315. before(function () {
  316. return chakram.post(
  317. '/domains/' + domain + '/rrsets/',
  318. {'subname': '*.foobar', 'type': 'AAAA', 'records': ['::1', 'bade::affe'], 'ttl': 60}
  319. );
  320. });
  321. itPropagatesToTheApi([
  322. {subname: '*.foobar', domain: domain, type: 'AAAA', ttl: 60, records: ['::1', 'bade::affe']},
  323. {subname: '*.foobar', domain: domain, type: 'AAAA', records: ['bade::affe', '::1']},
  324. ]);
  325. itShowsUpInPdnsAs('test.foobar', domain, 'AAAA', ['::1', 'bade::affe'], 60);
  326. });
  327. describe("cannot create RRsets with duplicate record content", function () {
  328. it("rejects exact duplicates", function () {
  329. return expect(chakram.post(
  330. '/domains/' + domain + '/rrsets/',
  331. {
  332. 'subname': 'duplicate-contents', 'type': 'AAAA',
  333. 'records': ['::1', '::1'], 'ttl': 60
  334. }
  335. )).to.have.status(422);
  336. });
  337. it("rejects semantic duplicates", function () {
  338. return expect(chakram.post(
  339. '/domains/' + domain + '/rrsets/',
  340. {
  341. 'subname': 'duplicate-contents', 'type': 'AAAA',
  342. 'records': ['::1', '::0001'], 'ttl': 60
  343. }
  344. )).to.have.status(422);
  345. });
  346. });
  347. describe("can bulk-post an AAAA and an MX record", function () {
  348. before(function () {
  349. var response = chakram.post(
  350. '/domains/' + domain + '/rrsets/',
  351. [
  352. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  353. { 'subname': '', 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  354. ]
  355. );
  356. expect(response).to.have.status(201);
  357. expect(response).to.have.schema(schemas.rrsets);
  358. return chakram.wait();
  359. });
  360. itPropagatesToTheApi([
  361. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  362. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  363. ]);
  364. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  365. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  366. });
  367. describe("cannot bulk-post with missing or invalid fields", function () {
  368. before(function () {
  369. // Set an RRset that we'll try to overwrite
  370. var response = chakram.post(
  371. '/domains/' + domain + '/rrsets/',
  372. {'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}
  373. );
  374. expect(response).to.have.status(201);
  375. var response = chakram.post(
  376. '/domains/' + domain + '/rrsets/',
  377. [
  378. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  379. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  380. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  381. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  382. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  383. {'subname': 'd.1', 'ttl': 50, 'type': 'SOA', 'records': ['ns1.desec.io. peter.desec.io. 2018034419 10800 3600 604800 60']},
  384. {'subname': 'd.1', 'ttl': 50, 'type': 'OPT', 'records': ['9999']},
  385. {'subname': 'd.1', 'ttl': 50, 'type': 'TYPE099', 'records': ['v=spf1 mx -all']},
  386. ]
  387. );
  388. expect(response).to.have.status(400);
  389. expect(response).to.have.json([
  390. { type: [ 'This field is required.' ] },
  391. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  392. { subname: [ 'This field is required.' ] },
  393. { ttl: [ 'This field is required.' ] },
  394. { records: [ 'This field is required.' ] },
  395. { type: [ 'You cannot tinker with the SOA RRset.' ] },
  396. { type: [ 'You cannot tinker with the OPT RRset.' ] },
  397. { type: [ 'Generic type format is not supported.' ] },
  398. ]);
  399. return chakram.wait();
  400. });
  401. it("does not propagate partially to the API", function () {
  402. return chakram.waitFor([
  403. chakram
  404. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  405. .then(function (response) {
  406. expect(response).to.have.status(404);
  407. }),
  408. chakram
  409. .get('/domains/' + domain + '/rrsets/.../TXT/')
  410. .then(function (response) {
  411. expect(response).to.have.status(200);
  412. expect(response).to.have.json('ttl', 50);
  413. expect(response.body.records).to.have.members(['"foo"']);
  414. }),
  415. ]);
  416. });
  417. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  418. });
  419. context("with a pre-existing RRset", function () {
  420. before(function () {
  421. var response = chakram.post(
  422. '/domains/' + domain + '/rrsets/',
  423. [
  424. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  425. {'subname': 'c.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  426. {'subname': 'delete-test', 'ttl': 50, 'type': 'A', 'records': ['127.1.2.3']},
  427. {'subname': 'replace-test-1', 'ttl': 50, 'type': 'AAAA', 'records': ['::1', '::2']},
  428. {'subname': 'replace-test-2', 'ttl': 50, 'type': 'AAAA', 'records': ['::1', '::2']},
  429. ]
  430. );
  431. return expect(response).to.have.status(201);
  432. });
  433. describe("can delete an RRset", function () {
  434. before(function () {
  435. var response = chakram.delete('/domains/' + domain + '/rrsets/delete-test.../A/');
  436. return expect(response).to.have.status(204);
  437. });
  438. itPropagatesToTheApi([
  439. {subname: 'delete-test', domain: domain, type: 'A', records: []},
  440. ]);
  441. itShowsUpInPdnsAs('delete-test', domain, 'A', []);
  442. });
  443. describe("can be replaced with a CNAME record", function () {
  444. before(function () {
  445. var response = chakram.put(
  446. '/domains/' + domain + '/rrsets/',
  447. [
  448. {'subname': 'replace-test-1', 'ttl': 50, 'type': 'AAAA', 'records': []},
  449. {'subname': 'replace-test-1', 'ttl': 1, 'type': 'CNAME', 'records': ['example.com.']},
  450. ]
  451. );
  452. return expect(response).to.have.status(200);
  453. });
  454. itPropagatesToTheApi([
  455. {subname: 'replace-test-1', domain: domain, type: 'AAAA', records: []},
  456. {subname: 'replace-test-1', domain: domain, type: 'CNAME', records: ["example.com."]},
  457. ]);
  458. itShowsUpInPdnsAs('replace-test-1', domain, 'AAAA', ["example.com"]);
  459. itShowsUpInPdnsAs('replace-test-1', domain, 'CNAME', ["example.com"]);
  460. });
  461. describe("cannot be replaced with a malformed CNAME record", function () {
  462. before(function () {
  463. var response = chakram.put(
  464. '/domains/' + domain + '/rrsets/',
  465. [
  466. {'subname': 'replace-test-2', 'ttl': 50, 'type': 'AAAA', 'records': []},
  467. {'subname': 'replace-test-2', 'ttl': 1, 'type': 'CNAME', 'records': ['no.trailing.dot']},
  468. ]
  469. );
  470. return expect(response).to.have.status(422);
  471. });
  472. itPropagatesToTheApi([
  473. {subname: 'replace-test-2', domain: domain, type: 'AAAA', records: ["::1", "::2"]},
  474. {subname: 'replace-test-2', domain: domain, type: 'CNAME', records: []},
  475. ]);
  476. itShowsUpInPdnsAs('replace-test-2', domain, 'AAAA', ["::1", "::2"]);
  477. itShowsUpInPdnsAs('replace-test-2', domain, 'CNAME', []);
  478. });
  479. describe("cannot bulk-post existing or duplicate RRsets", function () {
  480. var response;
  481. before(function () {
  482. response = chakram.post(
  483. '/domains/' + domain + '/rrsets/',
  484. [
  485. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  486. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  487. ]
  488. );
  489. expect(response).to.have.status(400);
  490. return chakram.wait();
  491. });
  492. it("gives the right response", function () {
  493. expect(response).to.have.json([
  494. {"__all__": ["Same subname and type as in position(s) 1, but must be unique."]},
  495. {"__all__": ["Same subname and type as in position(s) 0, but must be unique."]}
  496. ]);
  497. return chakram.wait();
  498. });
  499. it("does not touch records in the API", function () {
  500. return chakram
  501. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  502. .then(function (response) {
  503. expect(response).to.have.status(200);
  504. expect(response).to.have.json('ttl', 50);
  505. expect(response.body.records).to.have.members(['"foo"']);
  506. });
  507. });
  508. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"foo"'], 50);
  509. });
  510. describe("cannot delete RRsets via bulk-post", function () {
  511. var response;
  512. before(function () {
  513. response = chakram.post(
  514. '/domains/' + domain + '/rrsets/',
  515. [
  516. {'subname': 'c.2', 'ttl': 40, 'type': 'TXT', 'records': []},
  517. ]
  518. );
  519. return expect(response).to.have.status(400);
  520. });
  521. it("gives the right response", function () {
  522. return expect(response).to.have.json([
  523. {'records': ['This field must not be empty when using POST.']},
  524. ]);
  525. });
  526. });
  527. });
  528. describe("cannot bulk-post with invalid input", function () {
  529. it("gives the right response for invalid type", function () {
  530. var response = chakram.post(
  531. '/domains/' + domain + '/rrsets/',
  532. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  533. );
  534. return expect(response).to.have.status(422);
  535. });
  536. it("gives the right response for invalid records", function () {
  537. var response = chakram.post(
  538. '/domains/' + domain + '/rrsets/',
  539. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  540. );
  541. return expect(response).to.have.status(422);
  542. });
  543. it("gives the right response for records contents being null", function () {
  544. var response = chakram.post(
  545. '/domains/' + domain + '/rrsets/',
  546. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4', null]}]
  547. );
  548. return expect(response).to.have.status(400);
  549. });
  550. });
  551. });
  552. describe('PUT rrsets/ with fresh domain', function () {
  553. var domain = 'e2etest-' + require("uuid").v4() + '.' + publicSuffix;
  554. before(function () {
  555. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  556. });
  557. describe("can overwrite a single existing RRset using PUT", function () {
  558. before(function () {
  559. var response = chakram.post(
  560. '/domains/' + domain + '/rrsets/',
  561. { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
  562. ).then(function () {
  563. return chakram.put(
  564. '/domains/' + domain + '/rrsets/single.../AAAA/',
  565. { 'subname': 'single', 'type': 'AAAA', 'records': ['fefe::bade'], 'ttl': 31 }
  566. );
  567. });
  568. expect(response).to.have.status(200);
  569. expect(response).to.have.schema(schemas.rrset);
  570. return chakram.wait();
  571. });
  572. itPropagatesToTheApi([
  573. {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
  574. ]);
  575. itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
  576. });
  577. describe("can bulk-put an AAAA and an MX record", function () {
  578. before(function () {
  579. var response = chakram.put(
  580. '/domains/' + domain + '/rrsets/',
  581. [
  582. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  583. { 'subname': '', 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  584. ]
  585. );
  586. expect(response).to.have.status(200);
  587. expect(response).to.have.schema(schemas.rrsets);
  588. return chakram.wait();
  589. });
  590. itPropagatesToTheApi([
  591. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  592. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  593. ]);
  594. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  595. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  596. });
  597. describe("cannot bulk-put with missing or invalid fields", function () {
  598. before(function () {
  599. // Set an RRset that we'll try to overwrite
  600. var response = chakram.post(
  601. '/domains/' + domain + '/rrsets/',
  602. {'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}
  603. );
  604. expect(response).to.have.status(201);
  605. var response = chakram.put(
  606. '/domains/' + domain + '/rrsets/',
  607. [
  608. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  609. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  610. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  611. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  612. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  613. ]
  614. );
  615. expect(response).to.have.status(400);
  616. expect(response).to.have.json([
  617. { type: [ 'This field is required.' ] },
  618. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  619. { subname: [ 'This field is required.' ] },
  620. { ttl: [ 'This field is required.' ] },
  621. { records: [ 'This field is required.' ] },
  622. ]);
  623. return chakram.wait();
  624. });
  625. it("does not propagate partially to the API", function () {
  626. return chakram.waitFor([
  627. chakram
  628. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  629. .then(function (response) {
  630. expect(response).to.have.status(404);
  631. }),
  632. chakram
  633. .get('/domains/' + domain + '/rrsets/.../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(['"foo"']);
  638. }),
  639. ]);
  640. });
  641. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  642. });
  643. context("with a pre-existing RRset", function () {
  644. before(function () {
  645. var response = chakram.post(
  646. '/domains/' + domain + '/rrsets/',
  647. [
  648. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  649. {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  650. {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
  651. ]
  652. );
  653. expect(response).to.have.status(201);
  654. return chakram.wait();
  655. });
  656. describe("can bulk-put existing RRsets", function () {
  657. var response;
  658. before(function () {
  659. response = chakram.put(
  660. '/domains/' + domain + '/rrsets/',
  661. [
  662. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  663. ]
  664. );
  665. expect(response).to.have.status(200);
  666. expect(response).to.have.schema(schemas.rrsets);
  667. return chakram.wait();
  668. });
  669. it("does modify records in the API", function () {
  670. return chakram
  671. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  672. .then(function (response) {
  673. expect(response).to.have.status(200);
  674. expect(response).to.have.json('ttl', 40);
  675. expect(response.body.records).to.have.members(['"bar"']);
  676. });
  677. });
  678. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
  679. });
  680. describe("cannot bulk-put duplicate RRsets", function () {
  681. var response;
  682. before(function () {
  683. response = chakram.put(
  684. '/domains/' + domain + '/rrsets/',
  685. [
  686. {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
  687. {'subname': 'b.2', 'ttl': 60, 'type': 'TXT', 'records': ['"bar"']},
  688. ]
  689. );
  690. return expect(response).to.have.status(400);
  691. });
  692. it("gives the right response", function () {
  693. return expect(response).to.have.json([
  694. { '__all__': [ 'Same subname and type as in position(s) 1, but must be unique.' ] },
  695. { '__all__': [ 'Same subname and type as in position(s) 0, but must be unique.' ] },
  696. ]);
  697. });
  698. it("does not touch records in the API", function () {
  699. return chakram
  700. .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
  701. .then(function (response) {
  702. expect(response).to.have.status(200);
  703. expect(response).to.have.json('ttl', 50);
  704. expect(response.body.records).to.have.members(['"foo"']);
  705. });
  706. });
  707. itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
  708. });
  709. describe("can delete RRsets via bulk-put", function () {
  710. var response;
  711. before(function () {
  712. response = chakram.put(
  713. '/domains/' + domain + '/rrsets/',
  714. [
  715. {'subname': 'c.2', 'ttl': 40, 'type': 'A', 'records': []},
  716. ]
  717. );
  718. return expect(response).to.have.status(200);
  719. });
  720. it("gives the right response", function () {
  721. var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
  722. return expect(response).to.have.status(404);
  723. });
  724. });
  725. });
  726. describe("cannot bulk-put with invalid input", function () {
  727. it("gives the right response for invalid type", function () {
  728. var response = chakram.put(
  729. '/domains/' + domain + '/rrsets/',
  730. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  731. );
  732. return expect(response).to.have.status(422);
  733. });
  734. it("gives the right response for invalid records", function () {
  735. var response = chakram.put(
  736. '/domains/' + domain + '/rrsets/',
  737. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  738. );
  739. return expect(response).to.have.status(422);
  740. });
  741. it("gives the right response for records contents being null", function () {
  742. var response = chakram.put(
  743. '/domains/' + domain + '/rrsets/',
  744. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4', null]}]
  745. );
  746. return expect(response).to.have.status(400);
  747. });
  748. });
  749. });
  750. describe('PATCH rrsets/ with fresh domain', function () {
  751. var domain = 'e2etest-' + require("uuid").v4() + '.' + publicSuffix;
  752. before(function () {
  753. return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
  754. });
  755. describe("can modify a single existing RRset using PATCH", function () {
  756. before(function () {
  757. var response = chakram.post(
  758. '/domains/' + domain + '/rrsets/',
  759. { 'subname': 'single', 'type': 'AAAA', 'records': ['bade::fefe'], 'ttl': 62 }
  760. ).then(function () {
  761. return chakram.patch(
  762. '/domains/' + domain + '/rrsets/single.../AAAA/',
  763. { 'records': ['fefe::bade'], 'ttl': 31 }
  764. );
  765. });
  766. expect(response).to.have.status(200);
  767. expect(response).to.have.schema(schemas.rrset);
  768. return chakram.wait();
  769. });
  770. itPropagatesToTheApi([
  771. {subname: 'single', domain: domain, type: 'AAAA', ttl: 31, records: ['fefe::bade']},
  772. ]);
  773. itShowsUpInPdnsAs('single', domain, 'AAAA', ['fefe::bade'], 31);
  774. });
  775. describe("can bulk-patch an AAAA and an MX record", function () {
  776. before(function () {
  777. var response = chakram.patch(
  778. '/domains/' + domain + '/rrsets/',
  779. [
  780. { 'subname': 'ipv6', 'type': 'AAAA', 'records': ['dead::beef'], 'ttl': 22 },
  781. { 'subname': '', 'type': 'MX', 'records': ['10 mail.example.com.', '20 mail.example.net.'], 'ttl': 33 }
  782. ]
  783. );
  784. expect(response).to.have.status(200);
  785. expect(response).to.have.schema(schemas.rrsets);
  786. return chakram.wait();
  787. });
  788. itPropagatesToTheApi([
  789. {subname: 'ipv6', domain: domain, type: 'AAAA', ttl: 22, records: ['dead::beef']},
  790. {subname: '', domain: domain, type: 'MX', ttl: 33, records: ['10 mail.example.com.', '20 mail.example.net.']},
  791. ]);
  792. itShowsUpInPdnsAs('ipv6', domain, 'AAAA', ['dead::beef'], 22);
  793. itShowsUpInPdnsAs('', domain, 'MX', ['10 mail.example.com.', '20 mail.example.net.'], 33);
  794. });
  795. describe("cannot bulk-patch with missing or invalid fields", function () {
  796. before(function () {
  797. // Set an RRset that we'll try to overwrite
  798. var response = chakram.post(
  799. '/domains/' + domain + '/rrsets/',
  800. {'ttl': 50, 'type': 'TXT', 'records': ['"foo"']}
  801. );
  802. expect(response).to.have.status(201);
  803. var response = chakram.patch(
  804. '/domains/' + domain + '/rrsets/',
  805. [
  806. {'subname': 'a.1', 'records': ['dead::beef'], 'ttl': 22},
  807. {'subname': 'b.1', 'ttl': -50, 'type': 'AAAA', 'records': ['dead::beef']},
  808. {'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  809. {'subname': 'c.1', 'records': ['dead::beef'], 'type': 'AAAA'},
  810. {'subname': 'd.1', 'ttl': 50, 'type': 'AAAA'},
  811. ]
  812. );
  813. expect(response).to.have.status(400);
  814. expect(response).to.have.json([
  815. { type: [ 'This field is required.' ] },
  816. { ttl: [ 'Ensure this value is greater than or equal to 1.' ] },
  817. { subname: [ 'This field is required.' ] },
  818. { ttl: ['This field is required.']} ,
  819. { records: ['This field is required.']} ,
  820. ]);
  821. return chakram.wait();
  822. });
  823. it("does not propagate partially to the API", function () {
  824. return chakram.waitFor([
  825. chakram
  826. .get('/domains/' + domain + '/rrsets/b.1.../AAAA/')
  827. .then(function (response) {
  828. expect(response).to.have.status(404);
  829. }),
  830. chakram
  831. .get('/domains/' + domain + '/rrsets/.../TXT/')
  832. .then(function (response) {
  833. expect(response).to.have.status(200);
  834. expect(response).to.have.json('ttl', 50);
  835. expect(response.body.records).to.have.members(['"foo"']);
  836. }),
  837. ]);
  838. });
  839. itShowsUpInPdnsAs('b.1', domain, 'AAAA', []);
  840. });
  841. context("with a pre-existing RRset", function () {
  842. before(function () {
  843. var response = chakram.post(
  844. '/domains/' + domain + '/rrsets/',
  845. [
  846. {'subname': 'a.1', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  847. {'subname': 'a.2', 'ttl': 50, 'type': 'A', 'records': ['4.3.2.1']},
  848. {'subname': 'a.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  849. {'subname': 'b.2', 'ttl': 50, 'type': 'A', 'records': ['5.4.3.2']},
  850. {'subname': 'b.2', 'ttl': 50, 'type': 'TXT', 'records': ['"foo"']},
  851. {'subname': 'c.2', 'ttl': 50, 'type': 'A', 'records': ['1.2.3.4']},
  852. ]
  853. );
  854. return expect(response).to.have.status(201);
  855. });
  856. describe("can bulk-patch existing RRsets", function () {
  857. var response;
  858. before(function () {
  859. response = chakram.patch(
  860. '/domains/' + domain + '/rrsets/',
  861. [
  862. {'subname': 'a.1', 'type': 'TXT', 'records': ['"bar"']},
  863. {'subname': 'a.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  864. ]
  865. );
  866. expect(response).to.have.status(200);
  867. expect(response).to.have.schema(schemas.rrsets);
  868. return chakram.wait();
  869. });
  870. it("does modify records in the API", function () {
  871. return chakram.waitFor([
  872. chakram
  873. .get('/domains/' + domain + '/rrsets/a.1.../TXT/')
  874. .then(function (response) {
  875. expect(response).to.have.status(200);
  876. expect(response).to.have.json('ttl', 50);
  877. expect(response.body.records).to.have.members(['"bar"']);
  878. }),
  879. chakram
  880. .get('/domains/' + domain + '/rrsets/a.2.../TXT/')
  881. .then(function (response) {
  882. expect(response).to.have.status(200);
  883. expect(response).to.have.json('ttl', 40);
  884. expect(response.body.records).to.have.members(['"bar"']);
  885. }),
  886. ]);
  887. });
  888. itShowsUpInPdnsAs('a.2', domain, 'TXT', ['"bar"'], 40);
  889. });
  890. describe("cannot bulk-patch duplicate RRsets", function () {
  891. var response;
  892. before(function () {
  893. response = chakram.patch(
  894. '/domains/' + domain + '/rrsets/',
  895. [
  896. {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  897. {'subname': 'b.2', 'ttl': 40, 'type': 'TXT', 'records': ['"bar"']},
  898. ]
  899. );
  900. return expect(response).to.have.status(400);
  901. });
  902. it("gives the right response", function () {
  903. return expect(response).to.have.json([
  904. { '__all__': [ 'Same subname and type as in position(s) 1, but must be unique.' ] },
  905. { '__all__': [ 'Same subname and type as in position(s) 0, but must be unique.' ] },
  906. ]);
  907. });
  908. it("does not touch records in the API", function () {
  909. return chakram
  910. .get('/domains/' + domain + '/rrsets/b.2.../TXT/')
  911. .then(function (response) {
  912. expect(response).to.have.status(200);
  913. expect(response).to.have.json('ttl', 50);
  914. expect(response.body.records).to.have.members(['"foo"']);
  915. });
  916. });
  917. itShowsUpInPdnsAs('b.2', domain, 'TXT', ['"foo"'], 50);
  918. });
  919. describe("can delete RRsets via bulk-patch", function () {
  920. var response;
  921. before(function () {
  922. response = chakram.patch(
  923. '/domains/' + domain + '/rrsets/',
  924. [
  925. {'subname': 'c.2', 'type': 'A', 'records': []},
  926. ]
  927. );
  928. return expect(response).to.have.status(200);
  929. });
  930. it("gives the right response", function () {
  931. var response = chakram.get('/domains/' + domain + '/rrsets/c.2.../A/');
  932. return expect(response).to.have.status(404);
  933. });
  934. });
  935. });
  936. describe("cannot bulk-patch with invalid input", function () {
  937. it("gives the right response for invalid type", function () {
  938. var response = chakram.patch(
  939. '/domains/' + domain + '/rrsets/',
  940. [{'subname': 'a.2', 'ttl': 50, 'type': 'INVALID', 'records': ['"foo"']}]
  941. );
  942. return expect(response).to.have.status(422);
  943. });
  944. it("gives the right response for invalid records", function () {
  945. var response = chakram.patch(
  946. '/domains/' + domain + '/rrsets/',
  947. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4']}]
  948. );
  949. return expect(response).to.have.status(422);
  950. });
  951. it("gives the right response for records contents being null", function () {
  952. var response = chakram.patch(
  953. '/domains/' + domain + '/rrsets/',
  954. [{'subname': 'a.2', 'ttl': 50, 'type': 'MX', 'records': ['1.2.3.4', null]}]
  955. );
  956. return expect(response).to.have.status(400);
  957. });
  958. });
  959. });
  960. describe("auth/tokens/ endpoint", function () {
  961. var tokenId;
  962. var tokenValue;
  963. function createTokenWithName () {
  964. var tokenname = "e2e-token-" + require("uuid").v4();
  965. return chakram.post('/auth/tokens/', { name: tokenname }).then(function (response) {
  966. expect(response).to.have.status(201);
  967. expect(response).to.have.json('name', tokenname);
  968. tokenId = response.body['id'];
  969. });
  970. }
  971. function createToken () {
  972. return chakram.post('/auth/tokens/').then(function (response) {
  973. expect(response).to.have.status(201);
  974. tokenId = response.body['id'];
  975. tokenValue = response.body['value'];
  976. });
  977. }
  978. it("can create tokens", createToken);
  979. it("can create tokens with name", createTokenWithName)
  980. describe("with tokens", function () {
  981. before(createToken)
  982. it("a list of tokens can be retrieved", function () {
  983. var response = chakram.get('/auth/tokens/');
  984. return expect(response).to.have.schema(schemas.tokens);
  985. });
  986. describe("can delete token", function () {
  987. before( function () {
  988. var response = chakram.delete('/auth/tokens/' + tokenId + '/');
  989. return expect(response).to.have.status(204);
  990. });
  991. it("deactivates the token", function () {
  992. return expect(chakram.get('/auth/tokens/', {
  993. headers: {'Authorization': 'Token ' + tokenValue }
  994. })).to.have.status(401);
  995. });
  996. });
  997. it("deleting nonexistent tokens yields 204", function () {
  998. var response = chakram.delete('/auth/tokens/wedonthavethisid/');
  999. return expect(response).to.have.status(204);
  1000. });
  1001. });
  1002. })
  1003. });
  1004. });
  1005. });