3030 "dJS08nTeElUg6pn83A3hqWX+J testing"
3131)
3232
33+ ECDSA_PUBKEY = (
34+ "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAAB"
35+ "BBCGB0x9lmubbLJTF5NekCI0Cgjyip6jJh/t/qQQi1LAZisbREBJ8Wy+hwSn3tnbf/Imh9X"
36+ "+MQnrrza0jaQ3QUAQ= autotest@autotesting comment"
37+ )
38+
39+ ED25519_PUBKEY = (
40+ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAPYa7ztrkGyl/LSpBxv0DjPej74GCSVItX"
41+ "9Y2+/zxc+ testing"
42+ )
43+
44+ BAD_KEY = (
45+ "ssh-rsa foooooooooooooooooooooooooooooooooooooooooooooooooooobaaaaaaarrr"
46+ "rrrrr testing"
47+ )
48+
3349
3450@requests_mock .Mocker (real_http = True , adapter = adapter )
3551@mock .patch ('api.models.release.publish_release' , lambda * args : None )
@@ -61,17 +77,34 @@ def test_key_hook(self, mock_requests):
6177 response = self .client .post (url , body )
6278 self .assertEqual (response .status_code , 201 , response .data )
6379
64- # Create key
80+ # Create rsa key
6581 body = {'id' : str (self .user ), 'public' : RSA_PUBKEY }
6682 response = self .client .post ('/v2/keys' , body )
6783 self .assertEqual (response .status_code , 201 , response .data )
68- public = response .data ['public' ]
84+ rsa_pub = response .data ['public' ]
6985
70- # Create another keys
86+ # Create another rsa key
7187 body = {'id' : str (self .user ) + '-2' , 'public' : RSA_PUBKEY2 }
7288 response = self .client .post ('/v2/keys' , body )
7389 self .assertEqual (response .status_code , 201 , response .data )
74- public2 = response .data ['public' ]
90+ rsa_pub2 = response .data ['public' ]
91+
92+ # Create dsa key
93+ body = {'id' : str (self .user ) + '-3' , 'public' : ECDSA_PUBKEY }
94+ response = self .client .post ('/v2/keys' , body )
95+ self .assertEqual (response .status_code , 201 , response .data )
96+ dsa_pub = response .data ['public' ]
97+
98+ # Create ed25519 key
99+ body = {'id' : str (self .user ) + '-4' , 'public' : ED25519_PUBKEY }
100+ response = self .client .post ('/v2/keys' , body )
101+ self .assertEqual (response .status_code , 201 , response .data )
102+ ed25519_pub = response .data ['public' ]
103+
104+ # Attempt adding a bad SSH pubkey
105+ body = {'id' : str (self .user ) + '-5' , 'public' : BAD_KEY }
106+ response = self .client .post ('/v2/keys' , body )
107+ self .assertEqual (response .status_code , 400 , response .data )
75108
76109 # Make sure 404 is returned for a random app
77110 url = '/v2/hooks/keys/doesnotexist'
@@ -83,8 +116,10 @@ def test_key_hook(self, mock_requests):
83116 response = self .client .get (url , HTTP_X_DEIS_BUILDER_AUTH = settings .BUILDER_KEY )
84117 self .assertEqual (response .status_code , 200 , response .data )
85118 self .assertEqual (response .data , {"autotest" : [
86- {'key' : public , 'fingerprint' : '54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5' },
87- {'key' : public2 , 'fingerprint' : '43:fd:22:bc:dc:ca:6a:28:ba:71:4c:18:41:1d:d1:e2' }
119+ {'key' : rsa_pub , 'fingerprint' : '54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5' },
120+ {'key' : rsa_pub2 , 'fingerprint' : '43:fd:22:bc:dc:ca:6a:28:ba:71:4c:18:41:1d:d1:e2' },
121+ {'key' : dsa_pub , 'fingerprint' : '28:dd:ef:f9:12:ab:f9:80:6f:4c:0a:e7:e7:a4:59:95' },
122+ {'key' : ed25519_pub , 'fingerprint' : '75:9a:b3:81:13:40:c2:78:32:aa:e3:b4:93:2a:12:c9' }
88123 ]})
89124
90125 # Test against an app that exist but user does not
@@ -97,8 +132,11 @@ def test_key_hook(self, mock_requests):
97132 response = self .client .get (url , HTTP_X_DEIS_BUILDER_AUTH = settings .BUILDER_KEY )
98133 self .assertEqual (response .status_code , 200 , response .data )
99134 self .assertEqual (response .data , {"autotest" : [
100- {'key' : public , 'fingerprint' : '54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5' },
101- {'key' : public2 , 'fingerprint' : '43:fd:22:bc:dc:ca:6a:28:ba:71:4c:18:41:1d:d1:e2' }
135+ {'key' : rsa_pub , 'fingerprint' : '54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5' },
136+ {'key' : rsa_pub2 , 'fingerprint' : '43:fd:22:bc:dc:ca:6a:28:ba:71:4c:18:41:1d:d1:e2' },
137+ {'key' : dsa_pub , 'fingerprint' : '28:dd:ef:f9:12:ab:f9:80:6f:4c:0a:e7:e7:a4:59:95' },
138+ {'key' : ed25519_pub , 'fingerprint' : '75:9a:b3:81:13:40:c2:78:32:aa:e3:b4:93:2a:12:c9' }
139+
102140 ]})
103141
104142 # Fetch a valid ssh key
0 commit comments