Просмотр исходного кода

fix(e2e): adapt to new user management; get rid of hardcoded dedyn.io

Nils Wisiol 5 лет назад
Родитель
Сommit
fdd006bf4d
4 измененных файлов с 72 добавлено и 49 удалено
  1. 1 1
      api/api/settings.py
  2. 13 0
      test/e2e/setup.js
  3. 42 37
      test/e2e/spec/api_spec.js
  4. 16 11
      test/e2e/spec/dyndns_spec.js

+ 1 - 1
api/api/settings.py

@@ -130,7 +130,7 @@ DEFAULT_NS_TTL = os.environ['DESECSTACK_NSLORD_DEFAULT_TTL']
 
 # Public Suffix settings
 PSL_RESOLVER = os.environ.get('DESECSTACK_API_PSL_RESOLVER')
-LOCAL_PUBLIC_SUFFIXES = {'dedyn.io'}
+LOCAL_PUBLIC_SUFFIXES = {'dedyn.%s' % os.environ['DESECSTACK_DOMAIN']}
 
 # PowerDNS API access
 NSLORD_PDNS_API = 'http://nslord:8081/api/v1/servers/localhost'

+ 13 - 0
test/e2e/setup.js

@@ -230,5 +230,18 @@ function itShowsUpInPdnsAs(subname, domain, type, records, ttl) {
     });
 }
 
+/**
+ * Injects a CAPTCHA with correct solution
+ */
+function withCaptcha(f) {
+    return chakram.post('/captcha/', {}).then(function (response) {
+        return f({
+            "id": response.body.id,
+            "solution": response.body.content,
+        });
+    });
+}
+
 exports.itPropagatesToTheApi = itPropagatesToTheApi;
 exports.itShowsUpInPdnsAs = itShowsUpInPdnsAs;
+exports.withCaptcha = withCaptcha;

+ 42 - 37
test/e2e/spec/api_spec.js

@@ -3,6 +3,7 @@ var expect = chakram.expect;
 var itPropagatesToTheApi = require("./../setup.js").itPropagatesToTheApi;
 var itShowsUpInPdnsAs = require("./../setup.js").itShowsUpInPdnsAs;
 var schemas = require("./../schemas.js");
+var withCaptcha = require("./../setup.js").withCaptcha;
 
 describe("API Versioning", function () {
 
@@ -35,7 +36,7 @@ describe("API Versioning", function () {
 describe("API v1", function () {
     this.timeout(3000);
 
-    let publicSuffix = 'dedyn.io';  // TODO replace with env variable
+    let publicSuffix = 'dedyn.' + process.env.DESECSTACK_DOMAIN;  // see settings.py
 
     before(function () {
         chakram.setRequestDefaults({
@@ -45,18 +46,6 @@ describe("API v1", function () {
             followRedirect: false,
             baseUrl: 'https://www/api/v1',
         })
-
-        let credentials = {
-            "email":"admin@e2etest.local", "password": "password",
-            "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
-        };
-        return chakram.post('/auth/', credentials).then(function() {
-            chakram.post('/auth/login/', credentials).then(function (response) {
-                let config = {headers: {'Authorization': 'Token ' + response.body.auth_token}}
-                chakram.post('/domains/', {name: publicSuffix}, config)
-                // TODO verify behavior for non-existent local public suffixes
-            });
-        });
     });
 
     it("provides an index page", function () {
@@ -69,6 +58,14 @@ describe("API v1", function () {
 
     describe("user registration", function () {
 
+        var captcha;
+
+        before(function () {
+            return withCaptcha(function (_captcha) {
+                captcha = _captcha;
+            });
+        });
+
         it("returns a user object", function () {
             var email, password, token;
 
@@ -78,7 +75,7 @@ describe("API v1", function () {
             var response = chakram.post('/auth/', {
                 "email": email,
                 "password": password,
-                "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
+                "captcha": captcha,
             });
 
             return expect(response).to.have.status(202);
@@ -95,10 +92,12 @@ describe("API v1", function () {
             email = require("uuid").v4() + '@e2etest.local';
             password = require("uuid").v4();
 
-            var response = chakram.post('/auth/', {
-                "email": email,
-                "password": password,
-                "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
+            let response = withCaptcha(function (captcha) {
+                return chakram.post('/auth/', {
+                    "email": email,
+                    "password": password,
+                    "captcha": captcha,
+                });
             });
 
             return expect(response).to.have.status(202);
@@ -121,16 +120,18 @@ describe("API v1", function () {
                 email2 = require("uuid").v4() + '@e2etest.local';
                 password2 = require("uuid").v4();
 
-                return chakram.post('/auth/', {
-                    "email": email2,
-                    "password": password2,
-                    "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
-                }).then(function () {
-                    return chakram.post('/auth/login/', {
+                return withCaptcha(function (captcha) {
+                    return chakram.post('/auth/', {
                         "email": email2,
                         "password": password2,
-                    }).then(function (response) {
-                        token2 = response.body.auth_token
+                        "captcha": captcha,
+                    }).then(function () {
+                        return chakram.post('/auth/login/', {
+                            "email": email2,
+                            "password": password2,
+                        }).then(function (response) {
+                            token2 = response.body.auth_token
+                        });
                     });
                 });
             });
@@ -182,18 +183,20 @@ describe("API v1", function () {
             // register a user that we can login and work with
             password = require("uuid").v4();
 
-            return chakram.post('/auth/', {
-                "email": email,
-                "password": password,
-                "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
-            }).then(function () {
-                return chakram.post('/auth/login/', {
+            return withCaptcha(function (captcha) {
+                return chakram.post('/auth/', {
                     "email": email,
                     "password": password,
-                }).then(function (loginResponse) {
-                    expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
-                    token = loginResponse.body.auth_token;
-                    chakram.setRequestHeader('Authorization', 'Token ' + token);
+                    "captcha": captcha,
+                }).then(function () {
+                    return chakram.post('/auth/login/', {
+                        "email": email,
+                        "password": password,
+                    }).then(function (loginResponse) {
+                        expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
+                        token = loginResponse.body.auth_token;
+                        chakram.setRequestHeader('Authorization', 'Token ' + token);
+                    });
                 });
             });
         });
@@ -205,7 +208,9 @@ describe("API v1", function () {
                 var response;
 
                 before(function () {
-                    response = chakram.get('/');
+                    return chakram.get('/').then(function (_response) {
+                        response = _response;
+                    });
                 });
 
                 it('has status 200', function () {

+ 16 - 11
test/e2e/spec/dyndns_spec.js

@@ -2,9 +2,12 @@ var chakram = require("./../setup.js").chakram;
 var expect = chakram.expect;
 var itShowsUpInPdnsAs = require("./../setup.js").itShowsUpInPdnsAs;
 var schemas = require("./../schemas.js");
+var withCaptcha = require("./../setup.js").withCaptcha;
 
 describe("dyndns service", function () {
 
+    let publicSuffix = 'dedyn.' + process.env.DESECSTACK_DOMAIN;  // see settings.py
+
     before(function () {
         chakram.setRequestSettings({
             headers: {
@@ -24,23 +27,25 @@ describe("dyndns service", function () {
             // register a user that we can login and work with
             password = require("uuid").v4();
 
-            return chakram.post('/auth/', {
-                "email": email,
-                "password": password,
-                "captcha": {"id": "d7b5739e-9e14-40df-ac4a-1973777def5e", "solution": "no need for a solution when Django's DEBUG=True"},
-            }).then(function () {
-                return chakram.post('/auth/login/', {
+            return withCaptcha(function (captcha) {
+                return chakram.post('/auth/', {
                     "email": email,
                     "password": password,
-                }).then(function (loginResponse) {
-                    expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
-                    token = loginResponse.body.auth_token;
-                    chakram.setRequestHeader('Authorization', 'Token ' + token);
+                    "captcha": captcha,
+                }).then(function () {
+                    return chakram.post('/auth/login/', {
+                        "email": email,
+                        "password": password,
+                    }).then(function (loginResponse) {
+                        expect(loginResponse.body.auth_token).to.match(schemas.TOKEN_REGEX);
+                        token = loginResponse.body.auth_token;
+                        chakram.setRequestHeader('Authorization', 'Token ' + token);
+                    });
                 });
             });
         });
 
-        var domain = 'e2etest-' + require("uuid").v4() + '.dedyn.io';
+        var domain = 'e2etest-' + require("uuid").v4() + '.' + publicSuffix;
         describe("and domain [" + domain + "]", function () {
 
             before(function () {