##// END OF EJS Templates
tests: fixed SSH Key tests
marcink -
r3524:a87725c8 default
parent child Browse files
Show More
@@ -1,176 +1,176 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2019 RhodeCode GmbH
3 # Copyright (C) 2010-2019 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22
22
23 from rhodecode.model.db import User, UserSshKeys
23 from rhodecode.model.db import User, UserSshKeys
24
24
25 from rhodecode.tests import TestController, assert_session_flash
25 from rhodecode.tests import TestController, assert_session_flash
26 from rhodecode.tests.fixture import Fixture
26 from rhodecode.tests.fixture import Fixture
27
27
28 fixture = Fixture()
28 fixture = Fixture()
29
29
30
30
31 def route_path(name, params=None, **kwargs):
31 def route_path(name, params=None, **kwargs):
32 import urllib
32 import urllib
33 from rhodecode.apps._base import ADMIN_PREFIX
33 from rhodecode.apps._base import ADMIN_PREFIX
34
34
35 base_url = {
35 base_url = {
36 'edit_user_ssh_keys':
36 'edit_user_ssh_keys':
37 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys',
37 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys',
38 'edit_user_ssh_keys_generate_keypair':
38 'edit_user_ssh_keys_generate_keypair':
39 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/generate',
39 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/generate',
40 'edit_user_ssh_keys_add':
40 'edit_user_ssh_keys_add':
41 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/new',
41 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/new',
42 'edit_user_ssh_keys_delete':
42 'edit_user_ssh_keys_delete':
43 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/delete',
43 ADMIN_PREFIX + '/users/{user_id}/edit/ssh_keys/delete',
44
44
45 }[name].format(**kwargs)
45 }[name].format(**kwargs)
46
46
47 if params:
47 if params:
48 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
48 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
49 return base_url
49 return base_url
50
50
51
51
52 class TestAdminUsersSshKeysView(TestController):
52 class TestAdminUsersSshKeysView(TestController):
53 INVALID_KEY = """\
53 INVALID_KEY = """\
54 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vevJsuZds1iNU5
54 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vevJsuZds1iNU5
55 LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSykfR1D1TdluyIpQLrwgH5kb
55 LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSykfR1D1TdluyIpQLrwgH5kb
56 n8FkVI8zBMCKakxowvN67B0R7b1BT4PPzW2JlOXei/m9W12ZY484VTow6/B+kf2Q8
56 n8FkVI8zBMCKakxowvN67B0R7b1BT4PPzW2JlOXei/m9W12ZY484VTow6/B+kf2Q8
57 cP8tmCJmKWZma5Em7OTUhvjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6
57 cP8tmCJmKWZma5Em7OTUhvjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6
58 jvdphZTc30I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zP
58 jvdphZTc30I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zP
59 qPFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL
59 qPFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL
60 your_email@example.com
60 your_email@example.com
61 """
61 """
62 VALID_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vev' \
62 VALID_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vev' \
63 'JsuZds1iNU5LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSy' \
63 'JsuZds1iNU5LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSy' \
64 'kfR1D1TdluyIpQLrwgH5kbn8FkVI8zBMCKakxowvN67B0R7b1BT4PP' \
64 'kfR1D1TdluyIpQLrwgH5kbn8FkVI8zBMCKakxowvN67B0R7b1BT4PP' \
65 'zW2JlOXei/m9W12ZY484VTow6/B+kf2Q8cP8tmCJmKWZma5Em7OTUh' \
65 'zW2JlOXei/m9W12ZY484VTow6/B+kf2Q8cP8tmCJmKWZma5Em7OTUh' \
66 'vjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6jvdphZTc30' \
66 'vjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6jvdphZTc30' \
67 'I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zPq' \
67 'I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zPq' \
68 'PFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL ' \
68 'PFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL ' \
69 'your_email@example.com'
69 'your_email@example.com'
70 FINGERPRINT = 'MD5:01:4f:ad:29:22:6e:01:37:c9:d2:52:26:52:b0:2d:93'
70 FINGERPRINT = 'MD5:01:4f:ad:29:22:6e:01:37:c9:d2:52:26:52:b0:2d:93'
71
71
72 def test_ssh_keys_default_user(self):
72 def test_ssh_keys_default_user(self):
73 self.log_user()
73 self.log_user()
74 user = User.get_default_user()
74 user = User.get_default_user()
75 self.app.get(
75 self.app.get(
76 route_path('edit_user_ssh_keys', user_id=user.user_id),
76 route_path('edit_user_ssh_keys', user_id=user.user_id),
77 status=302)
77 status=302)
78
78
79 def test_add_ssh_key_error(self, user_util):
79 def test_add_ssh_key_error(self, user_util):
80 self.log_user()
80 self.log_user()
81 user = user_util.create_user()
81 user = user_util.create_user()
82 user_id = user.user_id
82 user_id = user.user_id
83
83
84 key_data = self.INVALID_KEY
84 key_data = self.INVALID_KEY
85
85
86 desc = 'MY SSH KEY'
86 desc = 'MY SSH KEY'
87 response = self.app.post(
87 response = self.app.post(
88 route_path('edit_user_ssh_keys_add', user_id=user_id),
88 route_path('edit_user_ssh_keys_add', user_id=user_id),
89 {'description': desc, 'key_data': key_data,
89 {'description': desc, 'key_data': key_data,
90 'csrf_token': self.csrf_token})
90 'csrf_token': self.csrf_token})
91 assert_session_flash(response, 'An error occurred during ssh '
91 assert_session_flash(response, 'An error occurred during ssh '
92 'key saving: Unable to decode the key')
92 'key saving: Unable to decode the key')
93
93
94 def test_ssh_key_duplicate(self, user_util):
94 def test_ssh_key_duplicate(self, user_util):
95 self.log_user()
95 self.log_user()
96 user = user_util.create_user()
96 user = user_util.create_user()
97 user_id = user.user_id
97 user_id = user.user_id
98
98
99 key_data = self.VALID_KEY
99 key_data = self.VALID_KEY
100
100
101 desc = 'MY SSH KEY'
101 desc = 'MY SSH KEY'
102 response = self.app.post(
102 response = self.app.post(
103 route_path('edit_user_ssh_keys_add', user_id=user_id),
103 route_path('edit_user_ssh_keys_add', user_id=user_id),
104 {'description': desc, 'key_data': key_data,
104 {'description': desc, 'key_data': key_data,
105 'csrf_token': self.csrf_token})
105 'csrf_token': self.csrf_token})
106 assert_session_flash(response, 'Ssh Key successfully created')
106 assert_session_flash(response, 'Ssh Key successfully created')
107 response.follow() # flush session flash
107 response.follow() # flush session flash
108
108
109 # add the same key AGAIN
109 # add the same key AGAIN
110 desc = 'MY SSH KEY'
110 desc = 'MY SSH KEY'
111 response = self.app.post(
111 response = self.app.post(
112 route_path('edit_user_ssh_keys_add', user_id=user_id),
112 route_path('edit_user_ssh_keys_add', user_id=user_id),
113 {'description': desc, 'key_data': key_data,
113 {'description': desc, 'key_data': key_data,
114 'csrf_token': self.csrf_token})
114 'csrf_token': self.csrf_token})
115
115
116 err = 'Such key with fingerprint `{}` already exists, ' \
116 err = 'Such key with fingerprint `{}` already exists, ' \
117 'please use a different one'.format(self.FINGERPRINT)
117 'please use a different one'.format(self.FINGERPRINT)
118 assert_session_flash(response, 'An error occurred during ssh key '
118 assert_session_flash(response, 'An error occurred during ssh key '
119 'saving: {}'.format(err))
119 'saving: {}'.format(err))
120
120
121 def test_add_ssh_key(self, user_util):
121 def test_add_ssh_key(self, user_util):
122 self.log_user()
122 self.log_user()
123 user = user_util.create_user()
123 user = user_util.create_user()
124 user_id = user.user_id
124 user_id = user.user_id
125
125
126 key_data = self.VALID_KEY
126 key_data = self.VALID_KEY
127
127
128 desc = 'MY SSH KEY'
128 desc = 'MY SSH KEY'
129 response = self.app.post(
129 response = self.app.post(
130 route_path('edit_user_ssh_keys_add', user_id=user_id),
130 route_path('edit_user_ssh_keys_add', user_id=user_id),
131 {'description': desc, 'key_data': key_data,
131 {'description': desc, 'key_data': key_data,
132 'csrf_token': self.csrf_token})
132 'csrf_token': self.csrf_token})
133 assert_session_flash(response, 'Ssh Key successfully created')
133 assert_session_flash(response, 'Ssh Key successfully created')
134
134
135 response = response.follow()
135 response = response.follow()
136 response.mustcontain(desc)
136 response.mustcontain(desc)
137
137
138 def test_delete_ssh_key(self, user_util):
138 def test_delete_ssh_key(self, user_util):
139 self.log_user()
139 self.log_user()
140 user = user_util.create_user()
140 user = user_util.create_user()
141 user_id = user.user_id
141 user_id = user.user_id
142
142
143 key_data = self.VALID_KEY
143 key_data = self.VALID_KEY
144
144
145 desc = 'MY SSH KEY'
145 desc = 'MY SSH KEY'
146 response = self.app.post(
146 response = self.app.post(
147 route_path('edit_user_ssh_keys_add', user_id=user_id),
147 route_path('edit_user_ssh_keys_add', user_id=user_id),
148 {'description': desc, 'key_data': key_data,
148 {'description': desc, 'key_data': key_data,
149 'csrf_token': self.csrf_token})
149 'csrf_token': self.csrf_token})
150 assert_session_flash(response, 'Ssh Key successfully created')
150 assert_session_flash(response, 'Ssh Key successfully created')
151 response = response.follow() # flush the Session flash
151 response = response.follow() # flush the Session flash
152
152
153 # now delete our key
153 # now delete our key
154 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
154 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
155 assert 1 == len(keys)
155 assert 1 == len(keys)
156
156
157 response = self.app.post(
157 response = self.app.post(
158 route_path('edit_user_ssh_keys_delete', user_id=user_id),
158 route_path('edit_user_ssh_keys_delete', user_id=user_id),
159 {'del_ssh_key': keys[0].ssh_key_id,
159 {'del_ssh_key': keys[0].ssh_key_id,
160 'csrf_token': self.csrf_token})
160 'csrf_token': self.csrf_token})
161
161
162 assert_session_flash(response, 'Ssh key successfully deleted')
162 assert_session_flash(response, 'Ssh key successfully deleted')
163 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
163 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
164 assert 0 == len(keys)
164 assert 0 == len(keys)
165
165
166 def test_generate_keypair(self, user_util):
166 def test_generate_keypair(self, user_util):
167 self.log_user()
167 self.log_user()
168 user = user_util.create_user()
168 user = user_util.create_user()
169 user_id = user.user_id
169 user_id = user.user_id
170
170
171 response = self.app.get(
171 response = self.app.get(
172 route_path('edit_user_ssh_keys_generate_keypair', user_id=user_id))
172 route_path('edit_user_ssh_keys_generate_keypair', user_id=user_id))
173
173
174 response.mustcontain('Private key')
174 response.mustcontain('Private key')
175 response.mustcontain('Public key')
175 response.mustcontain('Public key')
176 response.mustcontain('-----BEGIN RSA PRIVATE KEY-----')
176 response.mustcontain('-----BEGIN PRIVATE KEY-----')
@@ -1,163 +1,163 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2019 RhodeCode GmbH
3 # Copyright (C) 2010-2019 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22
22
23 from rhodecode.model.db import User, UserSshKeys
23 from rhodecode.model.db import User, UserSshKeys
24
24
25 from rhodecode.tests import TestController, assert_session_flash
25 from rhodecode.tests import TestController, assert_session_flash
26 from rhodecode.tests.fixture import Fixture
26 from rhodecode.tests.fixture import Fixture
27
27
28 fixture = Fixture()
28 fixture = Fixture()
29
29
30
30
31 def route_path(name, params=None, **kwargs):
31 def route_path(name, params=None, **kwargs):
32 import urllib
32 import urllib
33 from rhodecode.apps._base import ADMIN_PREFIX
33 from rhodecode.apps._base import ADMIN_PREFIX
34
34
35 base_url = {
35 base_url = {
36 'my_account_ssh_keys':
36 'my_account_ssh_keys':
37 ADMIN_PREFIX + '/my_account/ssh_keys',
37 ADMIN_PREFIX + '/my_account/ssh_keys',
38 'my_account_ssh_keys_generate':
38 'my_account_ssh_keys_generate':
39 ADMIN_PREFIX + '/my_account/ssh_keys/generate',
39 ADMIN_PREFIX + '/my_account/ssh_keys/generate',
40 'my_account_ssh_keys_add':
40 'my_account_ssh_keys_add':
41 ADMIN_PREFIX + '/my_account/ssh_keys/new',
41 ADMIN_PREFIX + '/my_account/ssh_keys/new',
42 'my_account_ssh_keys_delete':
42 'my_account_ssh_keys_delete':
43 ADMIN_PREFIX + '/my_account/ssh_keys/delete',
43 ADMIN_PREFIX + '/my_account/ssh_keys/delete',
44 }[name].format(**kwargs)
44 }[name].format(**kwargs)
45
45
46 if params:
46 if params:
47 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
47 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
48 return base_url
48 return base_url
49
49
50
50
51 class TestMyAccountSshKeysView(TestController):
51 class TestMyAccountSshKeysView(TestController):
52 INVALID_KEY = """\
52 INVALID_KEY = """\
53 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vevJsuZds1iNU5
53 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vevJsuZds1iNU5
54 LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSykfR1D1TdluyIpQLrwgH5kb
54 LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSykfR1D1TdluyIpQLrwgH5kb
55 n8FkVI8zBMCKakxowvN67B0R7b1BT4PPzW2JlOXei/m9W12ZY484VTow6/B+kf2Q8
55 n8FkVI8zBMCKakxowvN67B0R7b1BT4PPzW2JlOXei/m9W12ZY484VTow6/B+kf2Q8
56 cP8tmCJmKWZma5Em7OTUhvjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6
56 cP8tmCJmKWZma5Em7OTUhvjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6
57 jvdphZTc30I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zP
57 jvdphZTc30I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zP
58 qPFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL
58 qPFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL
59 your_email@example.com
59 your_email@example.com
60 """
60 """
61 VALID_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vev' \
61 VALID_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk+77sjDzVeB6vev' \
62 'JsuZds1iNU5LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSy' \
62 'JsuZds1iNU5LANOa5CU5G/9JYIA6RYsWWMO7mbsR82IUckdqOHmxSy' \
63 'kfR1D1TdluyIpQLrwgH5kbn8FkVI8zBMCKakxowvN67B0R7b1BT4PP' \
63 'kfR1D1TdluyIpQLrwgH5kbn8FkVI8zBMCKakxowvN67B0R7b1BT4PP' \
64 'zW2JlOXei/m9W12ZY484VTow6/B+kf2Q8cP8tmCJmKWZma5Em7OTUh' \
64 'zW2JlOXei/m9W12ZY484VTow6/B+kf2Q8cP8tmCJmKWZma5Em7OTUh' \
65 'vjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6jvdphZTc30' \
65 'vjyQVNz3v7HfeY5Hq0Ci4ECJ59hepFDabJvtAXg9XrI6jvdphZTc30' \
66 'I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zPq' \
66 'I4fG8+hBHzpeFxUGvSGNtXPUbwaAY8j/oHYrTpMgkj6pUEFsiKfC5zPq' \
67 'PFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL ' \
67 'PFR5HyKTCHW0nFUJnZsbyFT5hMiF/hZkJc9A0ZbdSvJwCRQ/g3bmdL ' \
68 'your_email@example.com'
68 'your_email@example.com'
69 FINGERPRINT = 'MD5:01:4f:ad:29:22:6e:01:37:c9:d2:52:26:52:b0:2d:93'
69 FINGERPRINT = 'MD5:01:4f:ad:29:22:6e:01:37:c9:d2:52:26:52:b0:2d:93'
70
70
71 def test_add_ssh_key_error(self, user_util):
71 def test_add_ssh_key_error(self, user_util):
72 user = user_util.create_user(password='qweqwe')
72 user = user_util.create_user(password='qweqwe')
73 self.log_user(user.username, 'qweqwe')
73 self.log_user(user.username, 'qweqwe')
74
74
75 key_data = self.INVALID_KEY
75 key_data = self.INVALID_KEY
76
76
77 desc = 'MY SSH KEY'
77 desc = 'MY SSH KEY'
78 response = self.app.post(
78 response = self.app.post(
79 route_path('my_account_ssh_keys_add'),
79 route_path('my_account_ssh_keys_add'),
80 {'description': desc, 'key_data': key_data,
80 {'description': desc, 'key_data': key_data,
81 'csrf_token': self.csrf_token})
81 'csrf_token': self.csrf_token})
82 assert_session_flash(response, 'An error occurred during ssh '
82 assert_session_flash(response, 'An error occurred during ssh '
83 'key saving: Unable to decode the key')
83 'key saving: Unable to decode the key')
84
84
85 def test_ssh_key_duplicate(self, user_util):
85 def test_ssh_key_duplicate(self, user_util):
86 user = user_util.create_user(password='qweqwe')
86 user = user_util.create_user(password='qweqwe')
87 self.log_user(user.username, 'qweqwe')
87 self.log_user(user.username, 'qweqwe')
88 key_data = self.VALID_KEY
88 key_data = self.VALID_KEY
89
89
90 desc = 'MY SSH KEY'
90 desc = 'MY SSH KEY'
91 response = self.app.post(
91 response = self.app.post(
92 route_path('my_account_ssh_keys_add'),
92 route_path('my_account_ssh_keys_add'),
93 {'description': desc, 'key_data': key_data,
93 {'description': desc, 'key_data': key_data,
94 'csrf_token': self.csrf_token})
94 'csrf_token': self.csrf_token})
95 assert_session_flash(response, 'Ssh Key successfully created')
95 assert_session_flash(response, 'Ssh Key successfully created')
96 response.follow() # flush session flash
96 response.follow() # flush session flash
97
97
98 # add the same key AGAIN
98 # add the same key AGAIN
99 desc = 'MY SSH KEY'
99 desc = 'MY SSH KEY'
100 response = self.app.post(
100 response = self.app.post(
101 route_path('my_account_ssh_keys_add'),
101 route_path('my_account_ssh_keys_add'),
102 {'description': desc, 'key_data': key_data,
102 {'description': desc, 'key_data': key_data,
103 'csrf_token': self.csrf_token})
103 'csrf_token': self.csrf_token})
104
104
105 err = 'Such key with fingerprint `{}` already exists, ' \
105 err = 'Such key with fingerprint `{}` already exists, ' \
106 'please use a different one'.format(self.FINGERPRINT)
106 'please use a different one'.format(self.FINGERPRINT)
107 assert_session_flash(response, 'An error occurred during ssh key '
107 assert_session_flash(response, 'An error occurred during ssh key '
108 'saving: {}'.format(err))
108 'saving: {}'.format(err))
109
109
110 def test_add_ssh_key(self, user_util):
110 def test_add_ssh_key(self, user_util):
111 user = user_util.create_user(password='qweqwe')
111 user = user_util.create_user(password='qweqwe')
112 self.log_user(user.username, 'qweqwe')
112 self.log_user(user.username, 'qweqwe')
113
113
114 key_data = self.VALID_KEY
114 key_data = self.VALID_KEY
115
115
116 desc = 'MY SSH KEY'
116 desc = 'MY SSH KEY'
117 response = self.app.post(
117 response = self.app.post(
118 route_path('my_account_ssh_keys_add'),
118 route_path('my_account_ssh_keys_add'),
119 {'description': desc, 'key_data': key_data,
119 {'description': desc, 'key_data': key_data,
120 'csrf_token': self.csrf_token})
120 'csrf_token': self.csrf_token})
121 assert_session_flash(response, 'Ssh Key successfully created')
121 assert_session_flash(response, 'Ssh Key successfully created')
122
122
123 response = response.follow()
123 response = response.follow()
124 response.mustcontain(desc)
124 response.mustcontain(desc)
125
125
126 def test_delete_ssh_key(self, user_util):
126 def test_delete_ssh_key(self, user_util):
127 user = user_util.create_user(password='qweqwe')
127 user = user_util.create_user(password='qweqwe')
128 user_id = user.user_id
128 user_id = user.user_id
129 self.log_user(user.username, 'qweqwe')
129 self.log_user(user.username, 'qweqwe')
130
130
131 key_data = self.VALID_KEY
131 key_data = self.VALID_KEY
132
132
133 desc = 'MY SSH KEY'
133 desc = 'MY SSH KEY'
134 response = self.app.post(
134 response = self.app.post(
135 route_path('my_account_ssh_keys_add'),
135 route_path('my_account_ssh_keys_add'),
136 {'description': desc, 'key_data': key_data,
136 {'description': desc, 'key_data': key_data,
137 'csrf_token': self.csrf_token})
137 'csrf_token': self.csrf_token})
138 assert_session_flash(response, 'Ssh Key successfully created')
138 assert_session_flash(response, 'Ssh Key successfully created')
139 response = response.follow() # flush the Session flash
139 response = response.follow() # flush the Session flash
140
140
141 # now delete our key
141 # now delete our key
142 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
142 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
143 assert 1 == len(keys)
143 assert 1 == len(keys)
144
144
145 response = self.app.post(
145 response = self.app.post(
146 route_path('my_account_ssh_keys_delete'),
146 route_path('my_account_ssh_keys_delete'),
147 {'del_ssh_key': keys[0].ssh_key_id,
147 {'del_ssh_key': keys[0].ssh_key_id,
148 'csrf_token': self.csrf_token})
148 'csrf_token': self.csrf_token})
149
149
150 assert_session_flash(response, 'Ssh key successfully deleted')
150 assert_session_flash(response, 'Ssh key successfully deleted')
151 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
151 keys = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).all()
152 assert 0 == len(keys)
152 assert 0 == len(keys)
153
153
154 def test_generate_keypair(self, user_util):
154 def test_generate_keypair(self, user_util):
155 user = user_util.create_user(password='qweqwe')
155 user = user_util.create_user(password='qweqwe')
156 self.log_user(user.username, 'qweqwe')
156 self.log_user(user.username, 'qweqwe')
157
157
158 response = self.app.get(
158 response = self.app.get(
159 route_path('my_account_ssh_keys_generate'))
159 route_path('my_account_ssh_keys_generate'))
160
160
161 response.mustcontain('Private key')
161 response.mustcontain('Private key')
162 response.mustcontain('Public key')
162 response.mustcontain('Public key')
163 response.mustcontain('-----BEGIN RSA PRIVATE KEY-----')
163 response.mustcontain('-----BEGIN PRIVATE KEY-----')
General Comments 0
You need to be logged in to leave comments. Login now