瀏覽代碼

feat(test): e2e tests for dyndns12 endpoint

Nils Wisiol 7 年之前
父節點
當前提交
06342fe5b1
共有 3 個文件被更改,包括 342 次插入5 次删除
  1. 2 2
      api/desecapi/views.py
  2. 339 0
      test/e2e/spec/dyndns_spec.js
  3. 1 3
      test/e2e/spec/www_spec.js

+ 2 - 2
api/desecapi/views.py

@@ -232,11 +232,11 @@ class Root(APIView):
             return Response({
                 'domains': reverse('domain-list'),
                 'user': reverse('user'),
-                'logout': reverse('logout'),
+                'logout': reverse('token-destroy'),  # TODO change interface to token-destroy, too?
             })
         else:
             return Response({
-                'login': reverse('login', request=request, format=format),
+                'login': reverse('token-create', request=request, format=format),  # TODO change interface to token-create, too?
                 'register': reverse('register', request=request, format=format),
             })
 

+ 339 - 0
test/e2e/spec/dyndns_spec.js

@@ -0,0 +1,339 @@
+var chakram = require("./../setup.js").chakram;
+var expect = chakram.expect;
+
+describe("dyndns service", function () {
+
+    var apiHomeSchema = {
+        properties: {
+            domains: {type: "string"},
+            logout: {type: "string"},
+            user: {type: "string"},
+        },
+        required: ["domains", "logout", "user"]
+    };
+
+    before(function () {
+        chakram.setRequestSettings({
+            headers: {
+                'Host': 'desec.' + process.env.DESECSTACK_DOMAIN,
+            },
+            followRedirect: false,
+            baseUrl: 'https://www/api/v1',
+        });
+    });
+
+    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);
+        });
+
+    });
+
+    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(/^[a-z0-9]{40}$/);
+                token = loginResponse.body.auth_token;
+            });
+        });
+
+    });
+
+    var email = require("uuid").v4() + '@e2etest.local';
+    describe("with user account [" + email + "]", function () {
+
+        var password, token;
+
+        before(function () {
+            // 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(/^[a-z0-9]{40}$/);
+                    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("domains endpoint", function () {
+
+                it("can register a domain name", function () {
+                    var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
+                    return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
+                });
+
+            });
+
+            describe("a domain endpoint", function () {
+
+                var domain;
+
+                before(function () {
+                    domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
+                    return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
+                });
+
+                it("can set an IPv4 address", function () {
+                    return expect(chakram.post(
+                        '/domains/' + domain + '/rrsets/',
+                        {
+                            'subname': '',
+                            'type': 'A',
+                            'records': ['127.0.0.1'],
+                            'ttl': 60,
+                        }
+                    )).to.have.status(201);
+                });
+
+                it("can set an IPv6 address", function () {
+                    return expect(chakram.post(
+                        '/domains/' + domain + '/rrsets/',
+                        {
+                            'subname': '',
+                            'type': 'AAAA',
+                            'records': ['::1'],
+                            'ttl': 60,
+                        }
+                    )).to.have.status(201);
+                });
+
+            });
+
+        });
+
+        var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
+        describe("and domain [" + domain + "]", function () {
+
+            before(function () {
+                chakram.setRequestHeader('Authorization', 'Token ' + token);
+                return expect(chakram.post('/domains/', {'name': domain})).to.have.status(201);
+            });
+
+            describe("dyndns12 endpoint with basic auth", function () {
+
+                var apiAccessConfig;
+
+                before(function () {
+                    apiAccessConfig = {
+                        headers: {
+                            Host: 'desec.' + process.env.DESECSTACK_DOMAIN,
+                            Authorization: 'Token ' + token,
+                        }
+                    };
+                    chakram.setRequestHeader('Host', 'update.dedyn.' + process.env.DESECSTACK_DOMAIN);
+                    chakram.setRequestHeader('Authorization', 'Basic ' + require('btoa')(domain + ':' + token));
+                    chakram.setRequestHeader('Accept', '*/*');
+                    chakram.setBaseUrl('https://www');
+                });
+
+                describe("updates without any arguments", function () {
+
+                    before(function () {
+                        var response = chakram.get('/'); // TODO also try other URLs
+                        expect(response).to.have.body('good');
+                        expect(response).to.have.status(200);
+                        return chakram.wait();
+                    });
+
+                    it('propagate to the API', function () {
+                        var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../A/', apiAccessConfig);
+                        return expect(response).to.have.json('records', [process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127']);
+                    });
+
+                    it('propagate to pdns', function () {
+                        expect(chakram.resolve(domain, 'A')).to.have.members([process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127']);
+                        expect(chakram.resolve(domain, 'AAAA')).to.be.empty;
+                        return chakram.wait();
+                    });
+
+                });
+
+                describe("v4 updates by query parameter", function () {
+
+                    before(function () {
+                        var response = chakram.get('/update/?ip=1.2.3.4');
+                        expect(response).to.have.body('good');
+                        expect(response).to.have.status(200);
+                        return chakram.wait();
+                    });
+
+                    it('propagate to the API', function () {
+                        var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../A/', apiAccessConfig);
+                        return expect(response).to.have.json('records', ['1.2.3.4']);
+                    });
+
+                    it('propagate to pdns', function () {
+                        expect(chakram.resolve(domain, 'A')).to.have.members(['1.2.3.4']);
+                        expect(chakram.resolve(domain, 'AAAA')).to.be.empty;
+                        return chakram.wait();
+                    });
+
+                    describe("removes v4 address with empty query param", function () {
+
+                        before(function () {
+                            var response = chakram.get('/update/?ip=&ipv6=bade::affe');
+                            expect(response).to.have.body('good');
+                            expect(response).to.have.status(200);
+                            return chakram.wait();
+                        });
+
+                        it('propagate to the API (v4)', function () {
+                            var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../A/', apiAccessConfig);
+                            return expect(response).to.have.status(404);
+                        });
+
+                        it('propagate to the API (v6)', function () {
+                            var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../AAAA/', apiAccessConfig);
+                            return expect(response).to.have.json('records', ['bade::affe']);
+                        });
+
+                        it('propagate to pdns', function () {
+                            expect(chakram.resolve(domain, 'A')).to.be.empty;
+                            expect(chakram.resolve(domain, 'AAAA')).to.have.members(['bade::affe']);
+                            return chakram.wait();
+                        });
+
+                    });
+
+                });
+
+                describe("v6 updates by query parameter", function () {
+
+                    before(function () {
+                        var response = chakram.get('/update/?ipv6=dead::beef');
+                        expect(response).to.have.body('good');
+                        expect(response).to.have.status(200);
+                        return chakram.wait();
+                    });
+
+                    it('propagate to the API', function () {
+                        var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../AAAA/', apiAccessConfig);
+                        return expect(response).to.have.json('records', ['dead::beef']);
+                    });
+
+                    it('propagate to pdns', function () {
+                        expect(chakram.resolve(domain, 'AAAA')).to.have.members(['dead::beef']);
+                        expect(chakram.resolve(domain, 'A')).to.have.members([process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127']);  // taken from the v4 connection
+                        return chakram.wait();
+                    });
+
+                    describe("removes v6 address with empty query param", function () {
+
+                        before(function () {
+                            var response = chakram.get('/update/?ip=1.3.3.7&ipv6=');
+                            expect(response).to.have.body('good');
+                            expect(response).to.have.status(200);
+                            return chakram.wait();
+                        });
+
+                        it('propagate to the API (v4)', function () {
+                            var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../A/', apiAccessConfig);
+                            return expect(response).to.have.json('records', ['1.3.3.7']);
+                        });
+
+                        it('propagate to the API (v6)', function () {
+                            var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../AAAA/', apiAccessConfig);
+                            return expect(response).to.have.status(404);
+                        });
+
+                        it('propagate to pdns', function () {
+                            expect(chakram.resolve(domain, 'A')).to.have.members(['1.3.3.7']);
+                            expect(chakram.resolve(domain, 'AAAA')).to.be.empty;
+                            return chakram.wait();
+                        });
+
+                    });
+
+                });
+
+                describe("v4 and v6 updates by query parameter", function () {
+
+                    before(function () {
+                        var response = chakram.get('/update/?ip=192.168.1.1&ipv6=::1');
+                        expect(response).to.have.body('good');
+                        expect(response).to.have.status(200);
+                        return chakram.wait();
+                    });
+
+                    it('propagate to the API', function () {
+                        var response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../A/', apiAccessConfig);
+                        expect(response).to.have.json('records', ['192.168.1.1']);
+                        response = chakram.get('/api/v1/domains/' + domain + '/rrsets/.../AAAA/', apiAccessConfig);
+                        expect(response).to.have.json('records', ['::1']);
+                        return chakram.wait();
+                    });
+
+                    it('propagate to pdns', function () {
+                        expect(chakram.resolve(domain, 'AAAA')).to.have.members(['::1']);
+                        expect(chakram.resolve(domain, 'A')).to.have.members(['192.168.1.1']);
+                        return chakram.wait();
+                    });
+
+                });
+
+            });
+
+        });
+
+    });
+
+});

+ 1 - 3
test/e2e/spec/www_spec.js

@@ -60,7 +60,6 @@ describe("www/nginx", function () {
                 // if the correct address is returned. Hence, we will stick to some
                 // simple tests.
                 expect(response).to.have.body(REGEX_IPV6_ADDRESS);
-                expect(response).to.not.have.body(process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127');
                 return chakram.wait();
             });
 
@@ -137,8 +136,7 @@ describe("www/nginx", function () {
             // topologically not in the same place as the end user), it's hard
             // if the correct address is returned. Hence, we will stick to some
             // simple tests.
-            expect(response).to.have.body(/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/);
-            expect(response).to.not.have.body(process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127');
+            expect(response).to.have.body(REGEX_IPV6_ADDRESS);
             return chakram.wait();
         });