func (s *AuthorisedKeysKeysSuite) TestDeleteLastKeyForbidden(c *gc.C) { keys := []string{ sshtesting.ValidKeyOne.Key + " user@host", sshtesting.ValidKeyTwo.Key + " yetanotheruser@host", } writeAuthKeysFile(c, keys) err := ssh.DeleteKeys(testSSHUser, "user@host", sshtesting.ValidKeyTwo.Fingerprint) c.Assert(err, gc.ErrorMatches, "cannot delete all keys") }
func (s *AuthorisedKeysKeysSuite) TestDeleteKeysKeepsUnrecognised(c *gc.C) { firstKey := sshtesting.ValidKeyOne.Key + " user@host" writeAuthKeysFile(c, []string{firstKey, sshtesting.ValidKeyTwo.Key, "invalid-key"}) err := ssh.DeleteKeys(testSSHUser, "user@host") c.Assert(err, jc.ErrorIsNil) actual, err := ssh.ReadAuthorisedKeys(testSSHUser) c.Assert(err, jc.ErrorIsNil) c.Assert(actual, gc.DeepEquals, []string{"invalid-key", sshtesting.ValidKeyTwo.Key}) }
func (s *AuthorisedKeysKeysSuite) TestDeleteKeys(c *gc.C) { firstKey := sshtesting.ValidKeyOne.Key + " user@host" anotherKey := sshtesting.ValidKeyTwo.Key thirdKey := sshtesting.ValidKeyThree.Key + " anotheruser@host" writeAuthKeysFile(c, []string{firstKey, anotherKey, thirdKey}) err := ssh.DeleteKeys(testSSHUser, "user@host", sshtesting.ValidKeyTwo.Fingerprint) c.Assert(err, jc.ErrorIsNil) actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys) c.Assert(err, jc.ErrorIsNil) c.Assert(actual, gc.DeepEquals, []string{thirdKey}) }
func (s *AuthorisedKeysKeysSuite) TestDeleteNonExistentFingerprint(c *gc.C) { firstKey := sshtesting.ValidKeyOne.Key + " user@host" writeAuthKeysFile(c, []string{firstKey}) err := ssh.DeleteKeys(testSSHUser, sshtesting.ValidKeyTwo.Fingerprint) c.Assert(err, gc.ErrorMatches, "cannot delete non existent key: "+sshtesting.ValidKeyTwo.Fingerprint) }