Merge ~teknoraver/snappy-hwe-snaps/+git/captive-redirect:master into ~snappy-hwe-team/snappy-hwe-snaps/+git/captive-redirect:master

Proposed by Matteo Croce
Status: Merged
Approved by: Matteo Croce
Approved revision: 48ec1db781397020d8f5d6f464bd474553f08d75
Merged at revision: a10ecc6ddb9439708da44f861325df1c8ce11518
Proposed branch: ~teknoraver/snappy-hwe-snaps/+git/captive-redirect:master
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/captive-redirect:master
Diff against target: 591 lines (+452/-7)
14 files modified
README.md (+4/-0)
cmd/config/main.go (+23/-7)
cmd/config/main_test.go (+119/-0)
parts/plugins/x-go.py (+44/-0)
run-tests.sh (+80/-0)
snap/hooks/configure (+24/-0)
snapcraft.yaml (+22/-0)
spread.yaml (+50/-0)
tests/lib/prepare-all.sh (+26/-0)
tests/lib/prepare-each.sh (+15/-0)
tests/lib/restore-each.sh (+3/-0)
tests/main/disable/task.yaml (+8/-0)
tests/main/enable-all/task.yaml (+16/-0)
tests/main/enable-some/task.yaml (+18/-0)
Reviewer Review Type Date Requested Status
Jim Hodapp (community) Approve
Simon Fels Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+315937@code.launchpad.net

Description of the change

Add configure hook

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) wrote :

Needs tests and left a comment inline.

review: Needs Fixing
Revision history for this message
Simon Fels (morphis) :
Revision history for this message
Matteo Croce (teknoraver) :
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) :
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Simon Fels (morphis) wrote :

Still missing spread tests.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

The tests look good, some changes needed...see inline below.

review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) wrote :

I'd also like to see a test that verifies that traffic makes it from the external interface(s) and gets redirected to the portal destination.

Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Matteo Croce (teknoraver) :
Revision history for this message
Matteo Croce (teknoraver) wrote :

> I'd also like to see a test that verifies that traffic makes it from the
> external interface(s) and gets redirected to the portal destination.

That would involve a second VM with the the virtual ethernet bridged to the tested one

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Simon Fels (morphis) wrote :

I would like to see still a spread test covering the real functionality of this snap using some kind of network namespace + veth combination but considering we want to get the first part of this finally done approving this now.

review: Approve
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Agree with Simon's comment, approving.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/README.md b/README.md
index 16ce364..69d3bcc 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,10 @@ You can set multiple configuration options with the config command:
19```19```
20 $ captive-portal.config set active=true port=8080 interfaces=eth120 $ captive-portal.config set active=true port=8080 interfaces=eth1
21```21```
22The configuration options are:
23active=(true,false) activates or deactivates the redirect
24port=(1-65535) port to redirect to
25interfaces=... comma separated value of interface to redirect from, if empty redirects from all
22## Development26## Development
2327
24```28```
diff --git a/cmd/config/main.go b/cmd/config/main.go
index 1c1fd2a..535bc02 100644
--- a/cmd/config/main.go
+++ b/cmd/config/main.go
@@ -28,7 +28,7 @@ import (
28 "github.com/jessevdk/go-flags"28 "github.com/jessevdk/go-flags"
29)29)
3030
31var configFile = filepath.Join(os.Getenv("SNAP_DATA"), "config.json")31var configFile = filepath.Join(os.Getenv("SNAP_COMMON"), "config.json")
3232
33type config struct {33type config struct {
34 Active bool `json:"active"`34 Active bool `json:"active"`
@@ -72,11 +72,14 @@ func (c *config) saveConfig(path string) error {
7272
73// Convenience function which basically does 'iptables -t nat ...'73// Convenience function which basically does 'iptables -t nat ...'
74// to add rules to the nat table74// to add rules to the nat table
75func addRule(args ...string) error {75func run(args ...string) error {
76 cmd := exec.Command("iptables", append([]string{"-t", "nat"}, args...)...)76 cmd := exec.Command("iptables", append([]string{"-t", "nat"}, args...)...)
77 return cmd.Run()77 return cmd.Run()
78}78}
7979
80// Override run with a logging function in tests
81var addRule = run
82
80func clearRules() {83func clearRules() {
81 // Flush our custom 'captive' chain and delete it84 // Flush our custom 'captive' chain and delete it
82 addRule("-D", "PREROUTING", "-j", "captive")85 addRule("-D", "PREROUTING", "-j", "captive")
@@ -134,9 +137,9 @@ func applyRules() error {
134type statusCommand struct{}137type statusCommand struct{}
135138
136func (cmd *statusCommand) Execute(args []string) error {139func (cmd *statusCommand) Execute(args []string) error {
137 println("active:", cfg.Active)140 fmt.Println("active:", cfg.Active)
138 println("port:", cfg.Port)141 fmt.Println("port:", cfg.Port)
139 println("interfaces:", strings.Join(cfg.Interfaces, ", "))142 fmt.Println("interfaces:", strings.Join(cfg.Interfaces, ", "))
140143
141 return nil144 return nil
142}145}
@@ -157,9 +160,22 @@ func (cmd *setCommand) Execute(args []string) error {
157160
158 switch value := arg[i+1:]; arg[:i] {161 switch value := arg[i+1:]; arg[:i] {
159 case "active":162 case "active":
160 cfg.Active = value == "true"163 switch value {
164 case "true":
165 cfg.Active = true
166 case "false":
167 cfg.Active = false
168 default:
169 return fmt.Errorf("Invalid active status %s", value)
170 }
161 case "port":171 case "port":
162 port, _ := strconv.ParseUint(value, 0, 16)172 port, err := strconv.ParseUint(value, 0, 16)
173 if err != nil {
174 return err
175 }
176 if port == 0 {
177 return fmt.Errorf("Port can't be 0")
178 }
163 cfg.Port = uint16(port)179 cfg.Port = uint16(port)
164 case "interfaces":180 case "interfaces":
165 if len(value) > 0 {181 if len(value) > 0 {
diff --git a/cmd/config/main_test.go b/cmd/config/main_test.go
166new file mode 100644182new file mode 100644
index 0000000..dc7a1c1
--- /dev/null
+++ b/cmd/config/main_test.go
@@ -0,0 +1,119 @@
1//
2// Copyright (C) 2017 Canonical Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 3 as
6// published by the Free Software Foundation.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16package main
17
18import (
19 "os"
20 "testing"
21
22 "gopkg.in/check.v1"
23)
24
25const (
26 configPath = "/tmp/cr-config.json"
27 argsfile = "iptables.args"
28)
29
30// gopkg.in/check.v1 stuff
31func Test(t *testing.T) { check.TestingT(t) }
32
33type ClientSuite struct{}
34
35var _ = check.Suite(&ClientSuite{})
36
37func (s *ClientSuite) TestConfig(c *check.C) {
38
39 // Prepare two configuration structures
40 cfg1 := config{
41 Active: true,
42 Port: 8080,
43 Interfaces: []string{"eth2", "tun1"},
44 }
45 var cfg2 config
46
47 c.Assert(cfg1.saveConfig(configPath), check.IsNil)
48 defer os.Remove(configPath)
49 c.Assert(cfg2.loadConfig(configPath), check.IsNil)
50
51 c.Assert(cfg1, check.DeepEquals, cfg2)
52}
53
54var iptablesArgs [][]string
55
56func testRun(args ...string) error {
57 iptablesArgs = append(iptablesArgs, args)
58 return nil
59}
60
61func (s *ClientSuite) TestClear(c *check.C) {
62 // Mock iptables calls
63 iptablesArgs = [][]string{}
64 addRule = testRun
65
66 clearRules()
67
68 c.Assert(iptablesArgs, check.DeepEquals, [][]string{
69 {"-D", "PREROUTING", "-j", "captive"},
70 {"-F", "captive"},
71 {"-X", "captive"},
72 })
73}
74
75func (s *ClientSuite) TestApplyAll(c *check.C) {
76 // Mock iptables calls
77 iptablesArgs = [][]string{}
78 addRule = testRun
79
80 cfg = config{
81 Active: true,
82 Port: 54239,
83 }
84
85 applyRules()
86
87 c.Assert(iptablesArgs, check.DeepEquals, [][]string{
88 {"-D", "PREROUTING", "-j", "captive"},
89 {"-F", "captive"},
90 {"-X", "captive"},
91 {"-N", "captive"},
92 {"-I", "PREROUTING", "-j", "captive"},
93 {"-A", "captive", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "54239"},
94 })
95}
96
97func (s *ClientSuite) TestApplySome(c *check.C) {
98 // Mock iptables calls
99 iptablesArgs = [][]string{}
100 addRule = testRun
101
102 cfg = config{
103 Active: true,
104 Port: 1234,
105 Interfaces: []string{"eth4", "ppp2"},
106 }
107
108 applyRules()
109
110 c.Assert(iptablesArgs, check.DeepEquals, [][]string{
111 {"-D", "PREROUTING", "-j", "captive"},
112 {"-F", "captive"},
113 {"-X", "captive"},
114 {"-N", "captive"},
115 {"-I", "PREROUTING", "-j", "captive"},
116 {"-A", "captive", "-i", "eth4", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "1234"},
117 {"-A", "captive", "-i", "ppp2", "-p", "tcp", "-m", "multiport", "--dport", "80,443", "-j", "REDIRECT", "--to-ports", "1234"},
118 })
119}
diff --git a/parts/plugins/x-go.py b/parts/plugins/x-go.py
0new file mode 100644120new file mode 100644
index 0000000..2211de7
--- /dev/null
+++ b/parts/plugins/x-go.py
@@ -0,0 +1,44 @@
1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2#
3# Copyright (C) 2015, 2016 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import os
18
19import snapcraft
20import snapcraft.plugins.go
21
22DEBIAN_GOCODE_SRC_PATH = "/usr/share/gocode/src"
23
24class GoPlugin(snapcraft.plugins.go.GoPlugin):
25 def pull(self):
26 # Skip the pull step from GoPlugin here as it would repeat 90% of what
27 # we're doing here and will only conflict.
28 snapcraft.BasePlugin.pull(self)
29 os.makedirs(self._gopath_src, exist_ok=True)
30
31 if self.options.source:
32 go_package = self._get_local_go_package()
33 go_package_path = os.path.join(self._gopath_src, go_package)
34 if os.path.islink(go_package_path):
35 os.unlink(go_package_path)
36 os.makedirs(os.path.dirname(go_package_path), exist_ok=True)
37 os.symlink(self.sourcedir, go_package_path)
38 # We can't just add the gocode directory to GOPATH as go
39 # doesn't like this. Instead we're symlinking the necessary
40 # subdirectories from the gocode directory into our already
41 # existing GOPATH.
42 for dir in os.listdir(DEBIAN_GOCODE_SRC_PATH):
43 os.symlink(os.path.join(DEBIAN_GOCODE_SRC_PATH, dir),
44 os.path.join(self._gopath_src, dir))
diff --git a/run-tests.sh b/run-tests.sh
0new file mode 10075545new file mode 100755
index 0000000..92910b5
--- /dev/null
+++ b/run-tests.sh
@@ -0,0 +1,80 @@
1#!/bin/sh
2#
3# Copyright (C) 2016 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17set -e
18
19TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras"
20TESTS_EXTRAS_PATH=".tests-extras"
21
22# Display help.
23# This has to be in sync with the tests-extras/test-runner.sh script
24# functionalities as the parameters to this one are passed directly there
25show_help() {
26 exec cat <<'EOF'
27Usage: run-tests.sh [OPTIONS]
28
29This is fetch & forget script and what it does is to fetch the
30tests-extras repository and execute the run-tests.sh script from
31there passing arguments as-is.
32
33optional arguments:
34 --help Show this help message and exit
35 --channel Select another channel to build the base image from (default: stable)
36 --snap Extra snap to install
37 --debug Enable verbose debugging output
38 --test-from-channel Pull network-manager snap from the specified channel instead of building it from source
39 --force-new-image Force generating a new image used for testing
40EOF
41}
42
43# Clone the tests-extras repository
44clone_tests_extras() {
45 echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..."
46 git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1
47 if [ $? -ne 0 ]; then
48 echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.."
49 exit 1
50 fi
51}
52
53# Make sure the already cloned tests-extras repository is in a known and update
54# state before it is going to be used.
55restore_and_update_tests_extras() {
56 echo "INFO: Restoring and updating $TESTS_EXTRAS_PATH"
57 cd $TESTS_EXTRAS_PATH && git reset --hard && git clean -dfx && git pull
58 cd -
59}
60
61# ==============================================================================
62# This is fetch & forget script and what it does is to fetch the tests-extras
63# repo and execute the run-tests.sh script from there passing arguments as-is.
64#
65# The tests-extras repository ends up checked out in the snap tree but as a
66# hidden directory which is re-used since then.
67
68# Display help w/o fetching anything
69if [ "$1" = "--help" ]; then
70 show_help
71fi
72
73if [ -d "$TESTS_EXTRAS_PATH" ]; then
74 restore_and_update_tests_extras
75else
76 clone_tests_extras
77fi
78
79echo "INFO: Executing tests runner"
80cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@"
diff --git a/snap/hooks/configure b/snap/hooks/configure
0new file mode 10075581new file mode 100755
index 0000000..249f367
--- /dev/null
+++ b/snap/hooks/configure
@@ -0,0 +1,24 @@
1#!/bin/sh
2
3# Copyright (C) 2017 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17active=$(snapctl get active)
18port=$(snapctl get port)
19interfaces=$(snapctl get interfaces)
20
21# Exit after fresh installation
22[ -z "$active$port$interfaces" ] && exit 0
23
24exec $SNAP/bin/config set active="$active" port="$port" interfaces="$interfaces"
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 1bb3f5f..7e030be 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -1,3 +1,18 @@
1#
2# Copyright (C) 2017 Canonical Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 3 as
6# published by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
1name: captive-redirect16name: captive-redirect
2version: 117version: 1
3confinement: strict18confinement: strict
@@ -14,9 +29,16 @@ apps:
14 plugs:29 plugs:
15 - firewall-control30 - firewall-control
1631
32hooks:
33 configure:
34 plugs:
35 - firewall-control
36
17parts:37parts:
18 config:38 config:
19 plugin: go39 plugin: go
20 source: cmd/config40 source: cmd/config
21 snap:41 snap:
22 - bin42 - bin
43 build-packages:
44 - golang-go-flags-dev
diff --git a/spread.yaml b/spread.yaml
23new file mode 10064445new file mode 100644
index 0000000..3eefa0a
--- /dev/null
+++ b/spread.yaml
@@ -0,0 +1,50 @@
1#
2# Copyright (C) 2017 Canonical Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 3 as
6# published by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17project: captive-redirect
18
19environment:
20 PROJECT_PATH: /home/captive-redirect
21 TESTSLIB: $PROJECT_PATH/tests/lib
22 SNAP_NAME: captive-redirect
23 # Allow the host to pass the channel to use for the test rim
24 SNAP_CHANNEL: $(HOST:echo $SNAP_CHANNEL)
25
26backends:
27 qemu:
28 systems:
29 - ubuntu-core-16:
30 username: test
31 password: test
32
33# Put this somewhere where we have read-write access
34path: /home/captive-redirect
35
36exclude:
37 - .git
38
39prepare: |
40 . $TESTSLIB/prepare-all.sh
41
42suites:
43 tests/main/:
44 summary: Full-system tests for the captive-redirect snap
45 systems:
46 - ubuntu-core-16
47 prepare-each: |
48 . $TESTSLIB/prepare-each.sh
49 restore-each: |
50 . $TESTSLIB/restore-each.sh
diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh
0new file mode 10075551new file mode 100755
index 0000000..d47845f
--- /dev/null
+++ b/tests/lib/prepare-all.sh
@@ -0,0 +1,26 @@
1#!/bin/sh
2
3rm -f /home/captive-redirect/captive-redirect_*.snap
4
5# Setup classic snap and build the captive-redirect snap in there
6snap install --devmode --beta classic
7cat <<-EOF > /home/test/build-snap.sh
8#!/bin/sh
9set -ex
10apt update
11apt install -y snapcraft git
12cd /home/captive-redirect/
13snapcraft clean
14snapcraft
15EOF
16chmod +x /home/test/build-snap.sh
17sudo classic /home/test/build-snap.sh
18snap remove classic
19
20# Make sure we have a snap binary
21test -e /home/captive-redirect/captive-redirect_*.snap
22
23# Snapshot of the current snapd state for a later restore
24systemctl stop snapd.service snapd.socket
25tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd
26systemctl start snapd.socket
diff --git a/tests/lib/prepare-each.sh b/tests/lib/prepare-each.sh
0new file mode 10075527new file mode 100755
index 0000000..d983cef
--- /dev/null
+++ b/tests/lib/prepare-each.sh
@@ -0,0 +1,15 @@
1#!/bin/sh
2
3# Restore snapd state from backup
4systemctl stop snapd.service snapd.socket
5rm -rf /var/lib/snapd/*
6tar xzf $SPREAD_PATH/snapd-state.tar.gz -C /
7rm -rf /root/.snap
8systemctl start snapd.socket
9
10# Clean iptables
11iptables -t nat -F
12iptables -t nat -X
13
14snap install --dangerous /home/captive-redirect/captive-redirect_*.snap
15snap connect captive-redirect:firewall-control core
diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
0new file mode 10075516new file mode 100755
index 0000000..aa8f65c
--- /dev/null
+++ b/tests/lib/restore-each.sh
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3snap remove captive-redirect
diff --git a/tests/main/disable/task.yaml b/tests/main/disable/task.yaml
0new file mode 1006444new file mode 100644
index 0000000..ababdb0
--- /dev/null
+++ b/tests/main/disable/task.yaml
@@ -0,0 +1,8 @@
1summary: Verify that the redirect can be disabled
2
3execute: |
4 # Snap is installed, check that it's disabled
5 captive-redirect.config status |grep 'active: false'
6
7 # Check that we have no iptables rules
8 ! iptables-save |grep -- -j
diff --git a/tests/main/enable-all/task.yaml b/tests/main/enable-all/task.yaml
0new file mode 1006449new file mode 100644
index 0000000..4745acb
--- /dev/null
+++ b/tests/main/enable-all/task.yaml
@@ -0,0 +1,16 @@
1summary: Verify that the redirect can be enabled on all interfaces
2
3execute: |
4 # Enable the redirect on all interfaces
5 captive-redirect.config set active=true port=9000
6
7 captive-redirect.config status |grep 'active: true'
8 captive-redirect.config status |grep 'port: 9000'
9 captive-redirect.config status |grep 'interfaces: $'
10
11 # Check that we have the iptables rules
12 ipt=/tmp/rules.$$
13 iptables-save >$ipt
14
15 grep -- '-A PREROUTING -j captive' $ipt
16 grep -- '-A captive -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 9000' $ipt
diff --git a/tests/main/enable-some/task.yaml b/tests/main/enable-some/task.yaml
0new file mode 10064417new file mode 100644
index 0000000..5bf13f6
--- /dev/null
+++ b/tests/main/enable-some/task.yaml
@@ -0,0 +1,18 @@
1summary: Verify that the redirect can be enabled selectively on configured interfaces
2
3execute: |
4 # Enable the redirect on the configured interfaces
5 captive-redirect.config set active=true port=7689 interfaces=eth4,tun2
6
7 captive-redirect.config status |grep 'active: true'
8 captive-redirect.config status |grep 'port: 7689'
9 captive-redirect.config status |grep 'interfaces: .*eth4'
10 captive-redirect.config status |grep 'interfaces: .*tun2'
11
12 # Check that we have the iptables rules
13 ipt=/tmp/rules.$$
14 iptables-save >$ipt
15
16 grep -- '-A PREROUTING -j captive' $ipt
17 grep -- '-A captive -i eth4 -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 7689' $ipt
18 grep -- '-A captive -i tun2 -p tcp -m multiport --dports 80,443 -j REDIRECT --to-ports 7689' $ipt

Subscribers

People subscribed via source and target branches

to all changes: