本文整理汇总了Golang中github.com/snapcore/snapd/overlord/auth.NewAuthContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAuthContext函数的具体用法?Golang NewAuthContext怎么用?Golang NewAuthContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAuthContext函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAuthContextStoreIDFallback
func (as *authSuite) TestAuthContextStoreIDFallback(c *C) {
authContext := auth.NewAuthContext(as.state, nil)
storeID, err := authContext.StoreID("store-id")
c.Assert(err, IsNil)
c.Check(storeID, Equals, "store-id")
}
示例2: TestAuthContextDeviceForNonExistent
func (as *authSuite) TestAuthContextDeviceForNonExistent(c *C) {
authContext := auth.NewAuthContext(as.state, nil)
device, err := authContext.Device()
c.Check(err, IsNil)
c.Check(device, DeepEquals, &auth.DeviceState{})
}
示例3: TestAuthContextUpdateDeviceAuthOtherUpdate
func (as *authSuite) TestAuthContextUpdateDeviceAuthOtherUpdate(c *C) {
as.state.Lock()
device, _ := auth.Device(as.state)
otherUpdateDevice := *device
otherUpdateDevice.SessionMacaroon = "othe-session-macaroon"
otherUpdateDevice.KeyID = "KEYID"
err := auth.SetDevice(as.state, &otherUpdateDevice)
as.state.Unlock()
c.Check(err, IsNil)
sessionMacaroon := "the-device-macaroon"
authContext := auth.NewAuthContext(as.state, nil)
curDevice, err := authContext.UpdateDeviceAuth(device, sessionMacaroon)
c.Assert(err, IsNil)
as.state.Lock()
deviceFromState, err := auth.Device(as.state)
as.state.Unlock()
c.Check(err, IsNil)
c.Check(deviceFromState, DeepEquals, curDevice)
c.Check(curDevice, DeepEquals, &auth.DeviceState{
KeyID: "KEYID",
SessionMacaroon: sessionMacaroon,
})
}
示例4: TestAuthContextUpdateUserAuthOtherUpdate
func (as *authSuite) TestAuthContextUpdateUserAuthOtherUpdate(c *C) {
as.state.Lock()
user, _ := auth.NewUser(as.state, "username", "macaroon", []string{"discharge"})
otherUpdateUser := *user
otherUpdateUser.Macaroon = "macaroon2"
otherUpdateUser.StoreDischarges = []string{"other-discharges"}
err := auth.UpdateUser(as.state, &otherUpdateUser)
as.state.Unlock()
c.Assert(err, IsNil)
newDischarges := []string{"updated-discharge"}
authContext := auth.NewAuthContext(as.state, nil)
// last discharges win
curUser, err := authContext.UpdateUserAuth(user, newDischarges)
c.Assert(err, IsNil)
as.state.Lock()
userFromState, err := auth.User(as.state, user.ID)
as.state.Unlock()
c.Check(err, IsNil)
c.Check(userFromState, DeepEquals, curUser)
c.Check(curUser, DeepEquals, &auth.UserState{
ID: user.ID,
Username: "username",
Macaroon: "macaroon2",
Discharges: []string{"discharge"},
StoreMacaroon: "macaroon",
StoreDischarges: newDischarges,
})
}
示例5: TestAuthContextStoreIDFromEnv
func (as *authSuite) TestAuthContextStoreIDFromEnv(c *C) {
authContext := auth.NewAuthContext(as.state, nil)
os.Setenv("UBUNTU_STORE_ID", "env-store-id")
defer os.Unsetenv("UBUNTU_STORE_ID")
storeID, err := authContext.StoreID("")
c.Assert(err, IsNil)
c.Check(storeID, Equals, "env-store-id")
}
示例6: TestAuthContextMissingDeviceAssertions
func (as *authSuite) TestAuthContextMissingDeviceAssertions(c *C) {
// no assertions in state
authContext := auth.NewAuthContext(as.state, &testDeviceAssertions{nothing: true})
_, _, err := authContext.DeviceSessionRequest("NONCE")
c.Check(err, Equals, auth.ErrNoSerial)
storeID, err := authContext.StoreID("fallback")
c.Assert(err, IsNil)
c.Check(storeID, Equals, "fallback")
}
示例7: TestAuthContextDevice
func (as *authSuite) TestAuthContextDevice(c *C) {
device := &auth.DeviceState{Brand: "some-brand"}
as.state.Lock()
err := auth.SetDevice(as.state, device)
as.state.Unlock()
c.Check(err, IsNil)
authContext := auth.NewAuthContext(as.state, nil)
deviceFromState, err := authContext.Device()
c.Check(err, IsNil)
c.Check(deviceFromState, DeepEquals, device)
}
示例8: TestAuthContextWithDeviceAssertions
func (as *authSuite) TestAuthContextWithDeviceAssertions(c *C) {
// having assertions in state
authContext := auth.NewAuthContext(as.state, &testDeviceAssertions{})
req, serial, err := authContext.DeviceSessionRequest("NONCE-1")
c.Assert(err, IsNil)
c.Check(strings.Contains(string(req), "nonce: NONCE-1\n"), Equals, true)
c.Check(strings.Contains(string(req), "serial: 9999\n"), Equals, true)
c.Check(strings.Contains(string(serial), "serial: 9999\n"), Equals, true)
storeID, err := authContext.StoreID("store-id")
c.Assert(err, IsNil)
c.Check(storeID, Equals, "my-brand-store-id")
}
示例9: TestAuthContextUpdateUserAuthInvalid
func (as *authSuite) TestAuthContextUpdateUserAuthInvalid(c *C) {
as.state.Lock()
_, _ = auth.NewUser(as.state, "username", "macaroon", []string{"discharge"})
as.state.Unlock()
user := &auth.UserState{
ID: 102,
Username: "username",
Macaroon: "macaroon",
}
authContext := auth.NewAuthContext(as.state, nil)
_, err := authContext.UpdateUserAuth(user, nil)
c.Assert(err, ErrorMatches, "invalid user")
}
示例10: TestAuthContextUpdateDeviceAuth
func (as *authSuite) TestAuthContextUpdateDeviceAuth(c *C) {
as.state.Lock()
device, err := auth.Device(as.state)
as.state.Unlock()
c.Check(err, IsNil)
c.Check(device, DeepEquals, &auth.DeviceState{})
sessionMacaroon := "the-device-macaroon"
authContext := auth.NewAuthContext(as.state, nil)
device, err = authContext.UpdateDeviceAuth(device, sessionMacaroon)
c.Check(err, IsNil)
deviceFromState, err := authContext.Device()
c.Check(err, IsNil)
c.Check(deviceFromState, DeepEquals, device)
c.Check(deviceFromState.SessionMacaroon, DeepEquals, sessionMacaroon)
}
示例11: TestAuthContextUpdateUserAuth
func (as *authSuite) TestAuthContextUpdateUserAuth(c *C) {
as.state.Lock()
user, _ := auth.NewUser(as.state, "username", "macaroon", []string{"discharge"})
as.state.Unlock()
newDischarges := []string{"updated-discharge"}
authContext := auth.NewAuthContext(as.state, nil)
user, err := authContext.UpdateUserAuth(user, newDischarges)
c.Check(err, IsNil)
as.state.Lock()
userFromState, err := auth.User(as.state, user.ID)
as.state.Unlock()
c.Check(err, IsNil)
c.Check(userFromState, DeepEquals, user)
c.Check(userFromState.Discharges, DeepEquals, []string{"discharge"})
c.Check(user.StoreDischarges, DeepEquals, newDischarges)
}
示例12: New
// New creates a new Overlord with all its state managers.
func New() (*Overlord, error) {
o := &Overlord{
loopTomb: new(tomb.Tomb),
}
backend := &overlordStateBackend{
path: dirs.SnapStateFile,
ensureBefore: o.ensureBefore,
requestRestart: o.requestRestart,
}
s, err := loadState(backend)
if err != nil {
return nil, err
}
o.stateEng = NewStateEngine(s)
snapMgr, err := snapstate.Manager(s)
if err != nil {
return nil, err
}
o.snapMgr = snapMgr
o.stateEng.AddManager(o.snapMgr)
assertMgr, err := assertstate.Manager(s)
if err != nil {
return nil, err
}
o.assertMgr = assertMgr
o.stateEng.AddManager(o.assertMgr)
ifaceMgr, err := ifacestate.Manager(s, nil)
if err != nil {
return nil, err
}
o.ifaceMgr = ifaceMgr
o.stateEng.AddManager(o.ifaceMgr)
hookMgr, err := hookstate.Manager(s)
if err != nil {
return nil, err
}
o.hookMgr = hookMgr
o.stateEng.AddManager(o.hookMgr)
configMgr, err := configstate.Manager(s, hookMgr)
if err != nil {
return nil, err
}
o.configMgr = configMgr
deviceMgr, err := devicestate.Manager(s)
if err != nil {
return nil, err
}
o.deviceMgr = deviceMgr
o.stateEng.AddManager(o.deviceMgr)
// setting up the store
authContext := auth.NewAuthContext(s, o.deviceMgr)
sto := storeNew(nil, authContext)
s.Lock()
snapstate.ReplaceStore(s, sto)
s.Unlock()
return o, nil
}
示例13: TestAuthContextDeviceSessionRequestNilDeviceAssertions
func (as *authSuite) TestAuthContextDeviceSessionRequestNilDeviceAssertions(c *C) {
authContext := auth.NewAuthContext(as.state, nil)
_, _, err := authContext.DeviceSessionRequest("NONCE")
c.Check(err, Equals, auth.ErrNoSerial)
}