Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in an application-lifecycle interface #1229

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions interfaces/builtin/all.go
Expand Up @@ -29,6 +29,7 @@ var allInterfaces = []interfaces.Interface{
&LocationControlInterface{},
&LocationObserveInterface{},
&NetworkManagerInterface{},
NewApplicationLifecycleInterface(),
NewFirewallControlInterface(),
NewHomeInterface(),
NewLocaleControlInterface(),
Expand Down
1 change: 1 addition & 0 deletions interfaces/builtin/all_test.go
Expand Up @@ -36,6 +36,7 @@ func (s *AllSuite) TestInterfaces(c *C) {
c.Check(all, Contains, &builtin.BluezInterface{})
c.Check(all, Contains, &builtin.LocationControlInterface{})
c.Check(all, Contains, &builtin.LocationObserveInterface{})
c.Check(all, DeepContains, builtin.NewApplicationLifecycleInterface())
c.Check(all, DeepContains, builtin.NewFirewallControlInterface())
c.Check(all, DeepContains, builtin.NewHomeInterface())
c.Check(all, DeepContains, builtin.NewLocaleControlInterface())
Expand Down
32 changes: 32 additions & 0 deletions interfaces/builtin/application_lifecycle.go
@@ -0,0 +1,32 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package builtin

import (
"github.com/snapcore/snapd/interfaces"
)

// NewApplicationLifecycleInterface returns a new "application-lifecycle" interface.
func NewApplicationLifecycleInterface() interfaces.Interface {
return &commonInterface{
name: "application-lifecycle",
autoConnect: true,
}
}
122 changes: 122 additions & 0 deletions interfaces/builtin/application_lifecycle_test.go
@@ -0,0 +1,122 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package builtin_test

import (
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/builtin"
"github.com/snapcore/snapd/snap"
)

type ApplicationLifecycleInterfaceSuite struct {
iface interfaces.Interface
slot *interfaces.Slot
plug *interfaces.Plug
}

var _ = Suite(&ApplicationLifecycleInterfaceSuite{
iface: builtin.NewApplicationLifecycleInterface(),
slot: &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "unity", Type: snap.TypeApp},
Name: "app-manager",
Interface: "application-lifecycle",
},
},
plug: &interfaces.Plug{
PlugInfo: &snap.PlugInfo{
Snap: &snap.Info{SuggestedName: "other"},
Name: "myapp",
Interface: "application-lifecycle",
},
},
})

func (s *ApplicationLifecycleInterfaceSuite) TestName(c *C) {
c.Assert(s.iface.Name(), Equals, "application-lifecycle")
}

func (s *ApplicationLifecycleInterfaceSuite) TestSanitizeSlot(c *C) {
err := s.iface.SanitizeSlot(s.slot)
c.Assert(err, IsNil)
}

func (s *ApplicationLifecycleInterfaceSuite) TestSanitizePlug(c *C) {
err := s.iface.SanitizePlug(s.plug)
c.Assert(err, IsNil)
}

func (s *ApplicationLifecycleInterfaceSuite) TestSanitizeIncorrectInterface(c *C) {
c.Assert(func() { s.iface.SanitizeSlot(&interfaces.Slot{SlotInfo: &snap.SlotInfo{Interface: "other"}}) },
PanicMatches, `slot is not of interface "application-lifecycle"`)
c.Assert(func() { s.iface.SanitizePlug(&interfaces.Plug{PlugInfo: &snap.PlugInfo{Interface: "other"}}) },
PanicMatches, `plug is not of interface "application-lifecycle"`)
}

func (s *ApplicationLifecycleInterfaceSuite) TestUnusedSecuritySystems(c *C) {
systems := [...]interfaces.SecuritySystem{interfaces.SecurityAppArmor,
interfaces.SecuritySecComp, interfaces.SecurityDBus,
interfaces.SecurityUDev}
for _, system := range systems {
snippet, err := s.iface.PermanentPlugSnippet(s.plug, system)
c.Assert(err, IsNil)
c.Assert(snippet, IsNil)
snippet, err = s.iface.PermanentSlotSnippet(s.slot, system)
c.Assert(err, IsNil)
c.Assert(snippet, IsNil)
snippet, err = s.iface.ConnectedSlotSnippet(s.plug, s.slot, system)
c.Assert(err, IsNil)
c.Assert(snippet, IsNil)
}
snippet, err := s.iface.ConnectedPlugSnippet(s.plug, s.slot, interfaces.SecurityDBus)
c.Assert(err, IsNil)
c.Assert(snippet, IsNil)
snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, interfaces.SecurityUDev)
c.Assert(err, IsNil)
c.Assert(snippet, IsNil)
}

func (s *ApplicationLifecycleInterfaceSuite) TestUsedSecuritySystems(c *C) {
// connected plugs have a non-nil security snippet for apparmor
snippet, err := s.iface.ConnectedPlugSnippet(s.plug, s.slot, interfaces.SecurityAppArmor)
c.Assert(err, IsNil)
c.Assert(snippet, Not(IsNil))
}

func (s *ApplicationLifecycleInterfaceSuite) TestUnexpectedSecuritySystems(c *C) {
snippet, err := s.iface.PermanentPlugSnippet(s.plug, "foo")
c.Assert(err, Equals, interfaces.ErrUnknownSecurity)
c.Assert(snippet, IsNil)
snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, "foo")
c.Assert(err, Equals, interfaces.ErrUnknownSecurity)
c.Assert(snippet, IsNil)
snippet, err = s.iface.PermanentSlotSnippet(s.slot, "foo")
c.Assert(err, Equals, interfaces.ErrUnknownSecurity)
c.Assert(snippet, IsNil)
snippet, err = s.iface.ConnectedSlotSnippet(s.plug, s.slot, "foo")
c.Assert(err, Equals, interfaces.ErrUnknownSecurity)
c.Assert(snippet, IsNil)
}

func (s *ApplicationLifecycleInterfaceSuite) TestAutoConnect(c *C) {
c.Check(s.iface.AutoConnect(), Equals, true)
}