|
13 | 13 | from api.models import Domain |
14 | 14 | from scheduler import KubeException |
15 | 15 |
|
| 16 | +import idna |
| 17 | + |
16 | 18 |
|
17 | 19 | class DomainTest(APITestCase): |
18 | 20 |
|
@@ -73,18 +75,136 @@ def test_strip_dot(self): |
73 | 75 | expected = [data['domain'] for data in response.data['results']] |
74 | 76 | self.assertEqual([self.app_id, domain], expected, msg) |
75 | 77 |
|
| 78 | + def test_manage_idn_domain(self): |
| 79 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 80 | + test_domains = [ |
| 81 | + 'ドメイン.テスト', |
| 82 | + 'xn--eckwd4c7c.xn--zckzah', |
| 83 | + 'xn--80ahd1agd.ru', |
| 84 | + 'домена.ru', |
| 85 | + '*.домена.испытание', |
| 86 | + 'täst.königsgäßchen.de', |
| 87 | + 'xn--tst-qla.xn--knigsgsschen-lcb0w.de', |
| 88 | + 'ドメイン.xn--zckzah', |
| 89 | + 'xn--eckwd4c7c.テスト', |
| 90 | + 'täst.xn--knigsgsschen-lcb0w.de', |
| 91 | + '*.xn--tst-qla.königsgäßchen.de' |
| 92 | + ] |
| 93 | + for domain in test_domains: |
| 94 | + msg = "failed on '{}'".format(domain) |
| 95 | + |
| 96 | + # Generate ACE and Unicode variant for domain |
| 97 | + if domain.startswith("*."): |
| 98 | + ace_domain = "*." + idna.encode(domain[2:]).decode("utf-8", "strict") |
| 99 | + unicode_domain = "*." + idna.decode(ace_domain[2:]) |
| 100 | + else: |
| 101 | + ace_domain = idna.encode(domain).decode("utf-8", "strict") |
| 102 | + unicode_domain = idna.decode(ace_domain) |
| 103 | + |
| 104 | + # Create |
| 105 | + response = self.client.post(url, {'domain': domain}) |
| 106 | + self.assertEqual(response.status_code, 201, msg) |
| 107 | + |
| 108 | + # Fetch |
| 109 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 110 | + response = self.client.get(url) |
| 111 | + expected = [data['domain'] for data in response.data['results']] |
| 112 | + self.assertEqual([self.app_id, ace_domain], expected, msg) |
| 113 | + |
| 114 | + # Verify creation failure for same domain with different encoding |
| 115 | + if ace_domain != domain: |
| 116 | + response = self.client.post(url, {'domain': ace_domain}) |
| 117 | + self.assertEqual(response.status_code, 400, msg) |
| 118 | + |
| 119 | + # Verify creation failure for same domain with different encoding |
| 120 | + if unicode_domain != domain: |
| 121 | + response = self.client.post(url, {'domain': unicode_domain}) |
| 122 | + self.assertEqual(response.status_code, 400, msg) |
| 123 | + |
| 124 | + # Delete |
| 125 | + url = '/v2/apps/{app_id}/domains/{hostname}'.format(hostname=domain, |
| 126 | + app_id=self.app_id) |
| 127 | + response = self.client.delete(url) |
| 128 | + self.assertEqual(response.status_code, 204, msg) |
| 129 | + |
| 130 | + # Verify removal |
| 131 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 132 | + response = self.client.get(url) |
| 133 | + self.assertEqual(1, response.data['count'], msg) |
| 134 | + |
| 135 | + # verify only app domain is left |
| 136 | + expected = [data['domain'] for data in response.data['results']] |
| 137 | + self.assertEqual([self.app_id], expected, msg) |
| 138 | + |
| 139 | + # Use different encoding for creating and deleting (ACE) |
| 140 | + if ace_domain != domain: |
| 141 | + # Create |
| 142 | + response = self.client.post(url, {'domain': domain}) |
| 143 | + self.assertEqual(response.status_code, 201, msg) |
| 144 | + |
| 145 | + # Fetch |
| 146 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 147 | + response = self.client.get(url) |
| 148 | + expected = [data['domain'] for data in response.data['results']] |
| 149 | + self.assertEqual([self.app_id, ace_domain], expected, msg) |
| 150 | + |
| 151 | + # Delete |
| 152 | + url = '/v2/apps/{app_id}/domains/{hostname}'.format(hostname=ace_domain, |
| 153 | + app_id=self.app_id) |
| 154 | + response = self.client.delete(url) |
| 155 | + self.assertEqual(response.status_code, 204, msg) |
| 156 | + |
| 157 | + # Verify removal |
| 158 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 159 | + response = self.client.get(url) |
| 160 | + self.assertEqual(1, response.data['count'], msg) |
| 161 | + |
| 162 | + # verify only app domain is left |
| 163 | + expected = [data['domain'] for data in response.data['results']] |
| 164 | + self.assertEqual([self.app_id], expected, msg) |
| 165 | + |
| 166 | + # Use different encoding for creating and deleting (Unicode) |
| 167 | + if unicode_domain != domain: |
| 168 | + # Create |
| 169 | + response = self.client.post(url, {'domain': domain}) |
| 170 | + self.assertEqual(response.status_code, 201, msg) |
| 171 | + |
| 172 | + # Fetch |
| 173 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 174 | + response = self.client.get(url) |
| 175 | + expected = [data['domain'] for data in response.data['results']] |
| 176 | + self.assertEqual([self.app_id, ace_domain], expected, msg) |
| 177 | + |
| 178 | + # Delete |
| 179 | + url = '/v2/apps/{app_id}/domains/{hostname}'.format(hostname=unicode_domain, |
| 180 | + app_id=self.app_id) |
| 181 | + response = self.client.delete(url) |
| 182 | + self.assertEqual(response.status_code, 204, msg) |
| 183 | + |
| 184 | + # Verify removal |
| 185 | + url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
| 186 | + response = self.client.get(url) |
| 187 | + self.assertEqual(1, response.data['count'], msg) |
| 188 | + |
| 189 | + # verify only app domain is left |
| 190 | + expected = [data['domain'] for data in response.data['results']] |
| 191 | + self.assertEqual([self.app_id], expected, msg) |
| 192 | + |
76 | 193 | def test_manage_domain(self): |
77 | 194 | url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id) |
78 | 195 | test_domains = [ |
79 | 196 | 'test-domain.example.com', |
80 | 197 | 'django.paas-sandbox', |
| 198 | + 'django.paas--sandbox', |
81 | 199 | 'domain', |
82 | 200 | 'not.too.loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong', |
83 | 201 | '3com.com', |
| 202 | + 'domain1', |
| 203 | + '3333.xyz', |
84 | 204 | 'w3.example.com', |
85 | 205 | 'MYDOMAIN.NET', |
86 | 206 | 'autotest.127.0.0.1.xip.io', |
87 | | - '*.deis.example.com', |
| 207 | + '*.deis.example.com' |
88 | 208 | ] |
89 | 209 |
|
90 | 210 | for domain in test_domains: |
@@ -161,13 +281,12 @@ def test_manage_domain_invalid_domain(self): |
161 | 281 | test_domains = [ |
162 | 282 | 'this_is_an.invalid.domain', |
163 | 283 | 'this-is-an.invalid.1', |
164 | | - 'django.pass--sandbox', |
165 | | - 'domain1', |
166 | | - '3333.com', |
| 284 | + 'django.pa--assandbox', |
167 | 285 | 'too.looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong', |
168 | 286 | 'foo.*.bar.com', |
169 | 287 | '*', |
170 | | - 'a' * 300 |
| 288 | + 'a' * 300, |
| 289 | + '.'.join(['a'] * 128) |
171 | 290 | ] |
172 | 291 | for domain in test_domains: |
173 | 292 | msg = "failed on \"{}\"".format(domain) |
|
0 commit comments