@@ -107,29 +107,43 @@ def test_bad_key(self):
107107 response = self ._check_bad_key (BAD_KEY )
108108 self .assertEqual (response .data , {'public' : ['Key contains invalid base64 chars' ]})
109109
110- def _check_duplicate_key (self , pubkey , pubkey2 ):
110+ def _check_duplicate_fingerprint (self , pubkey , pubkey2 ):
111111 """
112112 Test that a user cannot add a duplicate key
113113 """
114114 url = '/v2/keys'
115+ # initial key
115116 body = {'id' : 'mykey@box.local' , 'public' : pubkey }
116117 response = self .client .post (url , body )
117118 self .assertEqual (response .status_code , 201 , response .data )
118- response = self .client .post (url , body )
119- self .assertEqual (response .status_code , 400 , response .data )
119+
120120 # test that adding a key with the same fingerprint fails
121121 body = {'id' : 'mykey2@box.local' , 'public' : pubkey }
122122 response = self .client .post (url , body )
123123 self .assertEqual (response .status_code , 400 , response .data )
124- body = {'id' : 'mykey2@box.local' , 'public' : pubkey2 }
124+ self .assertEqual (response .data , {'public' : ['Public Key is already in use' ]}, response .data ) # noqa
125+
126+ body = {'id' : 'mykey3@box.local' , 'public' : pubkey2 }
125127 response = self .client .post (url , body )
126128 self .assertEqual (response .status_code , 201 , response .data )
127129
128130 def test_rsa_duplicate_key (self ):
129- self ._check_duplicate_key (RSA_PUBKEY , RSA_PUBKEY2 )
131+ self ._check_duplicate_fingerprint (RSA_PUBKEY , RSA_PUBKEY2 )
130132
131133 def test_ecdsa_duplicate_key (self ):
132- self ._check_duplicate_key (ECDSA_PUBKEY , ECDSA_PUBKEY2 )
134+ self ._check_duplicate_fingerprint (ECDSA_PUBKEY , ECDSA_PUBKEY2 )
135+
136+ def test_duplicate_id (self ):
137+ url = '/v2/keys'
138+ body = {'id' : 'duplicae@box.local' , 'public' : RSA_PUBKEY }
139+ response = self .client .post (url , body )
140+ self .assertEqual (response .status_code , 201 , response .data )
141+
142+ # same name, diff key
143+ body = {'id' : 'duplicae@box.local' , 'public' : RSA_PUBKEY2 }
144+ response = self .client .post (url , body )
145+ self .assertEqual (response .status_code , 400 , response .data )
146+ self .assertEqual (response .data , {'id' : ['SSH Key with this id already exists.' ]}, response .data ) # noqa
133147
134148 def test_rsa_key_str (self ):
135149 """Test the text representation of a key"""
0 commit comments