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

git demo snap update - Bug 1595229 #593

Closed
wants to merge 7 commits into from
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bzrignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dist
htmlcov
__pycache__
docs/**.html
*~
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you :)

*.swp
28 changes: 28 additions & 0 deletions demos/git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This example builds git trunk. It demonstrates the use of the 'home'
plug to allow it access to the users home directory.

After building and installing the snap, you will need to run the following
command to grant it access to your home directory:

```sh
snap connect git:home ubuntu-core:home
```

Only access to the home directory is granted. You can see this containment
in action by attempting to initialize a repository in /tmp:

```sh
$ mkdir -p /tmp/foo
$ cd /tmp/foo
$ /snap/bin/git init
fatal: Could not change back to '/tmp/foo': No such file or directory
```

Initializing and using repositories in your home directory works fine:

```sh
$ mkdir -p $HOME/tmp/foo
$ cd $HOME/tmp/foo
$ /snap/bin/git init
Initialized empty Git repository in /home/ubuntu/tmp/foo/.git/
```
9 changes: 8 additions & 1 deletion demos/git/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ description: This example is not really production quality
confinement: strict

apps:
server:
git:
command: bin/git
# git will not have access to files outside of its containment
# until you run the following command after installing the snap:
# snap connect git:home ubuntu-core:home
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:
git will have access to files in the user's home directory when you run ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like emphasising access is contained by default. Requiring users to manually connect the home interface is a security measure and not a meaningless chore. I'm extended the text a bit to make things clearer.

# After connecting up the home interface it gains access to
# non-hidden files in home directories.
plugs:
- home

parts:
git:
Expand Down
31 changes: 31 additions & 0 deletions snaps_tests/demos_tests/test_git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# 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/>.

import snaps_tests


class GitTestCase(snaps_tests.SnapsTestCase):

snap_content_dir = 'git'

def test_git(self):
self.build_snap(self.snap_content_dir)
self.install_snap(self.snap_content_dir, 'git', '0')
self.snappy_testbed.run_command(['sudo', 'snap', 'connect',
'git:home', 'ubuntu-core:home'])
self.assertTrue(
self.snappy_testbed.run_command(['/snap/bin/git',
'--version']).startswith('git'))
Copy link
Contributor

@come-maiz come-maiz Jun 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test!
But I was thinking that you could do something like:
self.snappy_testbed.run_command(['mkdir', '-p', '$HOME/tmp/foo'])
self.snappy_testbed.run_command(['/snap/bin/git', 'init', '$HOME/tmp/foo'])

This might need some more work on the run helpers. I'm around to help.

Also, now that this is more extensively tested, would you mind removing the scenario in snaps_tests/demos/tests.py?