File: ids_test.go

package info (click to toggle)
adequate 0.17.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: python: 254; makefile: 111; sh: 75; ansic: 29
file content (70 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download
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
66
67
68
69
70
package main

import (
	"testing"

	"github.com/google/go-cmp/cmp"
)

const sampleSyvinitFileContents = `
# ignore
# USER=ignore
FOOUSER = "foo-user"#blahblah
FOO_GROUP	= 	'foo-group' # blah
FOO_GROUP=

`

func TestExtractSysvinitIDsFromFile(t *testing.T) {
	fname := "filename"
	want := []fileIDPair{
		{fname, systemID{value: "foo-user", kind: userType}},
		{fname, systemID{value: "foo-group", kind: groupType}},
	}
	got := extractSysvinitIDsFromFile(fname, []byte(sampleSyvinitFileContents))

	opts := cmp.AllowUnexported(fileIDPair{}, systemID{})
	if diff := cmp.Diff(want, got, opts); diff != "" {
		t.Errorf("extractSysvinitIDsFromFile() mismatch (-want +got):\n%s", diff)
	}
}

const sampleSystemdUnitFileContents = `
[Unit]
Description=Daemon for generating UUIDs
Documentation=man:uuidd(8)
Requires=uuidd.socket

[Service]
ExecStart=/usr/sbin/uuidd --socket-activation --cont-clock
Restart=no
User=invalid-user
Group=invalid-group
ProtectSystem=strict
ProtectHome=yes
PrivateDevices=yes
PrivateUsers=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
ReadWritePaths=/var/lib/libuuid/
SystemCallFilter=@default @file-system @basic-io @system-service @signal @io-event @network-io

[Install]
Also=uuidd.socket
`

func TestExtractSystemdIDsFromFile(t *testing.T) {
	fname := "filename"
	want := []fileIDPair{
		{fname, systemID{value: "invalid-user", kind: userType}},
		{fname, systemID{value: "invalid-group", kind: groupType}},
	}
	got := extractSystemdIDsFromFile(fname, []byte(sampleSystemdUnitFileContents))

	opts := cmp.AllowUnexported(fileIDPair{}, systemID{})
	if diff := cmp.Diff(want, got, opts); diff != "" {
		t.Errorf("extractSystemdIDsFromFile.check() mismatch (-want +got):\n%s", diff)
	}
}