1515from api .utils import fingerprint
1616
1717
18- PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfQkkUUoxpvcNMkvv7jqnfodgs37M2eBO" \
19- "APgLK+KNBMaZaaKB4GF1QhTCMfFhoiTW3rqa0J75bHJcdkoobtTHlK8XUrFqsquWyg3XhsT" \
20- "Yr/3RQQXvO86e2sF7SVDJqVtpnbQGc5SgNrHCeHJmf5HTbXSIjCO/AJSvIjnituT/SIAMGe" \
21- "Bw0Nq/iSltwYAek1hiKO7wSmLcIQ8U4A00KEUtalaumf2aHOcfjgPfzlbZGP0S0cuBwSqLr" \
22- "8b5XGPmkASNdUiuJY4MJOce7bFU14B7oMAy2xacODUs1momUeYtGI9T7X2WMowJaO7tP3Gl" \
23- "sgBMP81VfYTfYChAyJpKp2yoP autotest@autotesting comment"
18+ RSA_PUBKEY = (
19+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfQkkUUoxpvcNMkvv7jqnfodgs37M2eBO"
20+ "APgLK+KNBMaZaaKB4GF1QhTCMfFhoiTW3rqa0J75bHJcdkoobtTHlK8XUrFqsquWyg3XhsT"
21+ "Yr/3RQQXvO86e2sF7SVDJqVtpnbQGc5SgNrHCeHJmf5HTbXSIjCO/AJSvIjnituT/SIAMGe"
22+ "Bw0Nq/iSltwYAek1hiKO7wSmLcIQ8U4A00KEUtalaumf2aHOcfjgPfzlbZGP0S0cuBwSqLr"
23+ "8b5XGPmkASNdUiuJY4MJOce7bFU14B7oMAy2xacODUs1momUeYtGI9T7X2WMowJaO7tP3Gl"
24+ "sgBMP81VfYTfYChAyJpKp2yoP autotest@autotesting comment"
25+ )
26+
27+ ECDSA_PUBKEY = (
28+ "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAAB"
29+ "BBCGB0x9lmubbLJTF5NekCI0Cgjyip6jJh/t/qQQi1LAZisbREBJ8Wy+hwSn3tnbf/Imh9X"
30+ "+MQnrrza0jaQ3QUAQ= autotest@autotesting comment"
31+ )
2432
2533
2634@override_settings (CELERY_ALWAYS_EAGER = True )
@@ -34,12 +42,12 @@ def setUp(self):
3442 self .assertTrue (
3543 self .client .login (username = 'autotest' , password = 'password' ))
3644
37- def test_key (self ):
45+ def _check_key (self , pubkey ):
3846 """
3947 Test that a user can add, remove and manage their SSH public keys
4048 """
4149 url = '/api/keys'
42- body = {'id' : 'mykey@box.local' , 'public' : PUBKEY }
50+ body = {'id' : 'mykey@box.local' , 'public' : pubkey }
4351 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
4452 self .assertEqual (response .status_code , 201 )
4553 key_id = response .data ['id' ]
@@ -54,18 +62,30 @@ def test_key(self):
5462 response = self .client .delete (url )
5563 self .assertEqual (response .status_code , 204 )
5664
57- def test_key_duplicate (self ):
65+ def test_rsa_key (self ):
66+ self ._check_key (RSA_PUBKEY )
67+
68+ def test_ecdsa_key (self ):
69+ self ._check_key (ECDSA_PUBKEY )
70+
71+ def _check_duplicate_key (self , pubkey ):
5872 """
5973 Test that a user cannot add a duplicate key
6074 """
6175 url = '/api/keys'
62- body = {'id' : 'mykey@box.local' , 'public' : PUBKEY }
76+ body = {'id' : 'mykey@box.local' , 'public' : pubkey }
6377 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
6478 self .assertEqual (response .status_code , 201 )
6579 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
6680 self .assertEqual (response .status_code , 400 )
6781
68- def test_key_str (self ):
82+ def test_rsa_duplicate_key (self ):
83+ self ._check_duplicate_key (RSA_PUBKEY )
84+
85+ def test_ecdsa_duplicate_key (self ):
86+ self ._check_duplicate_key (ECDSA_PUBKEY )
87+
88+ def test_rsa_key_str (self ):
6989 """Test the text representation of a key"""
7090 url = '/api/keys'
7191 body = {'id' : 'autotest' , 'public' :
@@ -81,6 +101,6 @@ def test_key_str(self):
81101 key = Key .objects .get (uuid = response .data ['uuid' ])
82102 self .assertEqual (str (key ), 'ssh-rsa AAAAB3NzaC.../HJDw9QckTS0vN autotest@deis.io' )
83103
84- def test_key_fingerprint (self ):
85- fp = fingerprint (PUBKEY )
104+ def test_rsa_key_fingerprint (self ):
105+ fp = fingerprint (RSA_PUBKEY )
86106 self .assertEquals (fp , '54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5' )
0 commit comments