aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/spfinal_test.go
blob: 1683d92adf6b579f7ff151f8b8f60ddd28f1c4bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package app

import (
	"syscall"
	"testing"

	"hakurei.app/container"
	"hakurei.app/container/fhs"
	"hakurei.app/container/stub"
	"hakurei.app/hst"
	"hakurei.app/system"
	"hakurei.app/system/acl"
)

func TestSpFinalOp(t *testing.T) {
	checkOpBehaviour(t, []opBehaviourTestCase{
		{"nil extra invalid env", func(bool, bool) outcomeOp {
			return spFinalOp{}
		}, func() *hst.Config {
			c := hst.Template()
			// verify nil check behaviour
			c.ExtraPerms = append(c.ExtraPerms, hst.ExtraPermConfig{})
			// verify toContainer behaviour
			c.Container.Env["="] = "\x00"
			return c
		}, nil, []stub.Call{
			// this op configures the system state and does not make calls during toSystem
		}, newI().
			Ensure(m("/var/lib/hakurei/u0"), 0700).
			UpdatePermType(system.User, m("/var/lib/hakurei/u0"),
				acl.Execute).
			UpdatePermType(system.User, m("/var/lib/hakurei/u0/org.chromium.Chromium"),
				acl.Read, acl.Write, acl.Execute), nil, nil, func(state *outcomeStateParams) {
			state.params.Ops = new(container.Ops)
		}, []stub.Call{
			// this op configures the container state and does not make calls during toContainer
		}, nil, nil, &hst.AppError{
			Step: "flatten environment",
			Err:  syscall.EINVAL,
			Msg:  "invalid environment variable =",
		}},

		{"success", func(bool, bool) outcomeOp {
			return spFinalOp{}
		}, hst.Template, nil, []stub.Call{
			// this op configures the system state and does not make calls during toSystem
		}, newI().
			Ensure(m("/var/lib/hakurei/u0"), 0700).
			UpdatePermType(system.User, m("/var/lib/hakurei/u0"),
				acl.Execute).
			UpdatePermType(system.User, m("/var/lib/hakurei/u0/org.chromium.Chromium"),
				acl.Read, acl.Write, acl.Execute), nil, nil, func(state *outcomeStateParams) {
			state.params.Ops = new(container.Ops)
		}, []stub.Call{
			// this op configures the container state and does not make calls during toContainer
		}, &container.Params{
			Env: []string{
				"GOOGLE_API_KEY=AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
				"GOOGLE_DEFAULT_CLIENT_ID=77185425430.apps.googleusercontent.com",
				"GOOGLE_DEFAULT_CLIENT_SECRET=OTJgUOQcT7lO7GsGZq2G4IlT",
			},
			Ops: new(container.Ops).Remount(fhs.AbsRoot, syscall.MS_RDONLY),
		}, nil, nil},
	})
}