func (s *keyManagerSuite) TestNewKeyManagerAPIAcceptsEnvironManager(c *gc.C) { anAuthoriser := s.authoriser anAuthoriser.EnvironManager = true endPoint, err := keymanager.NewKeyManagerAPI(s.State, s.resources, anAuthoriser) c.Assert(err, jc.ErrorIsNil) c.Assert(endPoint, gc.NotNil) }
func (s *keyManagerSuite) TestAddJujuSystemKey(c *gc.C) { anAuthoriser := s.authoriser anAuthoriser.EnvironManager = true anAuthoriser.Tag = names.NewMachineTag("0") var err error s.keymanager, err = keymanager.NewKeyManagerAPI(s.State, s.resources, anAuthoriser) c.Assert(err, jc.ErrorIsNil) key1 := sshtesting.ValidKeyOne.Key + " user@host" key2 := sshtesting.ValidKeyTwo.Key initialKeys := []string{key1, key2} s.setAuthorisedKeys(c, strings.Join(initialKeys, "\n")) newKey := sshtesting.ValidKeyThree.Key + " juju-system-key" args := params.ModifyUserSSHKeys{ User: "******", Keys: []string{newKey}, } results, err := s.keymanager.AddKeys(args) c.Assert(err, jc.ErrorIsNil) c.Assert(results, gc.DeepEquals, params.ErrorResults{ Results: []params.ErrorResult{ {Error: nil}, }, }) s.assertEnvironKeys(c, append(initialKeys, newKey)) }
func (s *keyManagerSuite) TestNewKeyManagerAPIRefusesNonEnvironManager(c *gc.C) { anAuthoriser := s.authoriser anAuthoriser.Tag = names.NewMachineTag("99") anAuthoriser.EnvironManager = false endPoint, err := keymanager.NewKeyManagerAPI(s.State, s.resources, anAuthoriser) c.Assert(endPoint, gc.IsNil) c.Assert(err, gc.ErrorMatches, "permission denied") }
func (s *keyManagerSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) s.resources = common.NewResources() s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() }) s.authoriser = apiservertesting.FakeAuthorizer{ Tag: s.AdminUserTag(c), } var err error s.keymanager, err = keymanager.NewKeyManagerAPI(s.State, s.resources, s.authoriser) c.Assert(err, gc.IsNil) }
func (s *keyManagerSuite) TestAddJujuSystemKeyNotMachine(c *gc.C) { anAuthoriser := s.authoriser anAuthoriser.EnvironManager = true anAuthoriser.Tag = names.NewUnitTag("wordpress/0") var err error s.keymanager, err = keymanager.NewKeyManagerAPI(s.State, s.resources, anAuthoriser) c.Assert(err, gc.IsNil) key1 := sshtesting.ValidKeyOne.Key s.setAuthorisedKeys(c, key1) newKey := sshtesting.ValidKeyThree.Key + " juju-system-key" args := params.ModifyUserSSHKeys{ User: "******", Keys: []string{newKey}, } _, err = s.keymanager.AddKeys(args) c.Assert(err, gc.ErrorMatches, "permission denied") s.assertEnvironKeys(c, []string{key1}) }
func (s *keyManagerSuite) TestNewKeyManagerAPIAcceptsClient(c *gc.C) { endPoint, err := keymanager.NewKeyManagerAPI(s.State, s.resources, s.authoriser) c.Assert(err, jc.ErrorIsNil) c.Assert(endPoint, gc.NotNil) }