File: meta.bats

package info (click to toggle)
rust-pathrs 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,912 kB
  • sloc: python: 1,138; sh: 371; ansic: 259; makefile: 151
file content (77 lines) | stat: -rw-r--r-- 2,175 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
71
72
73
74
75
76
77
#!/usr/bin/bats -t
# SPDX-License-Identifier: MPL-2.0
#
# libpathrs: safe path resolution on Linux
# Copyright (C) 2019-2025 Aleksa Sarai <cyphar@cyphar.com>
# Copyright (C) 2019-2025 SUSE LLC
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

load helpers

function setup() {
	setup_tmpdirs
}

function teardown() {
	teardown_tmpdirs
}

# These are mainly meta-tests that ensure that pathrs-cmd supports certain
# specific features.

@test "pathrs-cmd [bad O_* flags]" {
	ROOT="$(setup_tmpdir)"

	touch "$ROOT/file"

	pathrs-cmd root --root "$ROOT" resolve --reopen O_BADFLAG file
	[ "$status" -ne 0 ]
	grep -F "O_BADFLAG" <<<"$output" # the error should mention the flag

	pathrs-cmd root --root "$ROOT" resolve --reopen badflag file
	[ "$status" -ne 0 ]
	grep -Fi "badflag" <<<"$output" # the error should mention the flag

	pathrs-cmd root --root "$ROOT" open --oflags O_BADFLAG file
	[ "$status" -ne 0 ]
	grep -F "O_BADFLAG" <<<"$output" # the error should mention the flag

	pathrs-cmd root --root "$ROOT" open --oflags badflag file
	[ "$status" -ne 0 ]
	grep -Fi "badflag" <<<"$output" # the error should mention the flag

	pathrs-cmd root --root "$ROOT" open --oflags rdonly,O_BADFLAG file
	[ "$status" -ne 0 ]
	grep -F "O_BADFLAG" <<<"$output" # the error should mention the flag

	pathrs-cmd root --root "$ROOT" open --oflags O_RDONLY,badflag file
	[ "$status" -ne 0 ]
	grep -Fi "badflag" <<<"$output" # the error should mention the flag
}

@test "pathrs-cmd [funky O_* flags]" {
	ROOT="$(setup_tmpdir)"

	echo "THIS SHOULD BE TRUNCATED" >"$ROOT/file"
	[ "$(stat -c '%s' "$ROOT/file")" -ne 0 ]
	chmod 0644 "$ROOT/file"

	pathrs-cmd root --root "$ROOT" open --oflags trunc file
	[ "$status" -eq 0 ]
	grep -Fx "FILE-PATH $ROOT/file" <<<"$output"

	sane_run stat -c '%F' "$ROOT/file"
	[[ "$output" == "regular empty file" ]]
	sane_run stat -c '%s' "$ROOT/file"
	[ "$output" -eq 0 ]
}

@test "pathrs-cmd mknod [bad type]" {
	ROOT="$(setup_tmpdir)"

	pathrs-cmd root --root "$ROOT" mknod file l
	[ "$status" -ne 0 ]
}