Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions overlord/snapstate/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func InstallComponents(
return nil, err
}

snapUserID, err := userIDForSnap(st, &snapst, opts.UserID)
if err != nil {
return nil, err
}

snapsup := SnapSetup{
Base: info.Base,
SideInfo: &info.SideInfo,
Expand All @@ -118,6 +123,7 @@ func InstallComponents(
Version: info.Version,
PlugsOnly: len(info.Slots) == 0,
InstanceKey: info.InstanceKey,
UserID: snapUserID,
ComponentExclusiveOperation: true,
}

Expand Down
37 changes: 35 additions & 2 deletions overlord/snapstate/component_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,30 @@ func (s *snapmgrTestSuite) TestInstallComponentsTransactionPerSnap(c *C) {
})
}

func (s *snapmgrTestSuite) TestInstallComponentsWithSnapStateAndInstallOptsUserIDs(c *C) {
s.testInstallComponents(c, testInstallComponentsOpts{
userIDSnapState: s.user.ID,
userIDInstallOpts: s.user2.ID,
})
}

func (s *snapmgrTestSuite) TestInstallComponentsWithUserIDSnapState(c *C) {
s.testInstallComponents(c, testInstallComponentsOpts{
userIDSnapState: s.user2.ID,
})
}

func (s *snapmgrTestSuite) TestInstallComponentsWithUserIDInstallOpts(c *C) {
s.testInstallComponents(c, testInstallComponentsOpts{
userIDInstallOpts: s.user.ID,
})
}

type testInstallComponentsOpts struct {
lane int
transaction client.TransactionType
lane int
transaction client.TransactionType
userIDInstallOpts int
userIDSnapState int
}

func (s *snapmgrTestSuite) testInstallComponents(c *C, opts testInstallComponentsOpts) {
Expand Down Expand Up @@ -1007,6 +1028,7 @@ func (s *snapmgrTestSuite) testInstallComponents(c *C, opts testInstallComponent
}),
Current: snapRev,
TrackingChannel: "channel-for-components",
UserID: opts.userIDSnapState,
})

components := []string{"standard-component", "kernel-modules-component"}
Expand Down Expand Up @@ -1038,6 +1060,7 @@ func (s *snapmgrTestSuite) testInstallComponents(c *C, opts testInstallComponent
}

installOpts := snapstate.Options{
UserID: opts.userIDInstallOpts,
Flags: snapstate.Flags{
Lane: opts.lane,
Transaction: opts.transaction,
Expand All @@ -1052,6 +1075,16 @@ func (s *snapmgrTestSuite) testInstallComponents(c *C, opts testInstallComponent
setupProfiles := setupTs.Tasks()[0]
c.Assert(setupProfiles.Kind(), Equals, "setup-profiles")

snapsupSetupProfiles, err := snapstate.TaskSnapSetup(setupProfiles)
c.Assert(err, IsNil)
var expectedUserID int
if opts.userIDSnapState != 0 {
expectedUserID = opts.userIDSnapState
} else {
expectedUserID = opts.userIDInstallOpts
}
c.Assert(snapsupSetupProfiles.UserID, Equals, expectedUserID)

prepareKmodComps := setupTs.Tasks()[1]
c.Assert(prepareKmodComps.Kind(), Equals, "prepare-kernel-modules-components")

Expand Down
38 changes: 33 additions & 5 deletions overlord/snapstate/handlers_components_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ func (s *downloadComponentSuite) TestDoDownloadComponentCustomBlobDir(c *C) {
})
}

func (s *downloadComponentSuite) TestDoDownloadComponentWithUserAuth(c *C) {
s.testDoDownloadComponent(c, testDoDownloadComponentOpts{
withUserAuth: true,
})
}

type testDoDownloadComponentOpts struct {
autoRefresh bool
blobDir string
autoRefresh bool
blobDir string
withUserAuth bool
}

func (s *downloadComponentSuite) testDoDownloadComponent(c *C, opts testDoDownloadComponentOpts) {
Expand All @@ -79,6 +86,20 @@ func (s *downloadComponentSuite) testDoDownloadComponent(c *C, opts testDoDownlo
tr.Set("core", "refresh.rate-limit", "1234B")
tr.Commit()

var userID int
var user *auth.UserState
if opts.withUserAuth {
var err error
user, err = auth.NewUser(s.state, auth.NewUserParams{
Username: "username",
Email: "email@test.com",
Macaroon: "user-macaroon",
Discharges: []string{"discharge"},
})
c.Assert(err, IsNil)
userID = user.ID
}

si := &snap.SideInfo{
RealName: "snap",
SnapID: snaptest.AssertedSnapID("snap"),
Expand All @@ -93,6 +114,7 @@ func (s *downloadComponentSuite) testDoDownloadComponent(c *C, opts testDoDownlo
InstanceKey: "key",
Flags: snapstate.Flags{IsAutoRefresh: opts.autoRefresh},
DownloadBlobDir: opts.blobDir,
UserID: userID,
})

t.Set("component-setup", &snapstate.ComponentSetup{
Expand Down Expand Up @@ -148,11 +170,17 @@ func (s *downloadComponentSuite) testDoDownloadComponent(c *C, opts testDoDownlo
}
}

var expectedMacaroon string
if opts.withUserAuth {
expectedMacaroon = user.StoreMacaroon
}

c.Check(s.fakeStore.downloads, DeepEquals, []fakeDownload{
{
name: "snap+comp",
target: expectedPath,
opts: downloadOpts,
name: "snap+comp",
target: expectedPath,
opts: downloadOpts,
macaroon: expectedMacaroon,
},
})
}
Expand Down
Loading