Skip to content

Commit 5bbb94c

Browse files
Nomadic Labsclaude
andcommitted
test: add integration tests for group validation and edge cases
- 57: network mismatch rejection on group add - 58: path traversal and invalid group name validation - 59: delete --cascade/--ungroup mutual exclusion and --ungroup behavior Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 87c645d commit 5bbb94c

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Test: Adding a service to a group with a different network should fail
3+
set -euo pipefail
4+
source /tests/lib.sh
5+
6+
test_init "Group add network mismatch"
7+
8+
GROUP_NAME="test-netmismatch-$$"
9+
TEST_INSTANCE="test-netmis-node-$$"
10+
RPC_PORT=$(alloc_port)
11+
12+
# Pre-cleanup
13+
om group delete "$GROUP_NAME" 2>/dev/null || true
14+
register_instance "$TEST_INSTANCE"
15+
16+
# ── Create group on shadownet ──
17+
echo "Creating group '$GROUP_NAME' on shadownet..."
18+
om group create "$GROUP_NAME" \
19+
--network shadownet \
20+
--octez-version 24.1 \
21+
--service-user tezos
22+
23+
# ── Install a node on a DIFFERENT network ──
24+
echo "Installing node '$TEST_INSTANCE' on ghostnet..."
25+
om install-node \
26+
--instance "$TEST_INSTANCE" \
27+
--network ghostnet \
28+
--snapshot \
29+
--snapshot-no-check \
30+
--snapshot-uri "$SANDBOX_URL/snapshot.rolling" \
31+
--rpc-addr "127.0.0.1:$RPC_PORT" \
32+
--service-user tezos \
33+
--no-enable 2>&1 || true
34+
35+
if ! instance_exists "$TEST_INSTANCE"; then
36+
echo "ERROR: Node instance not created"
37+
exit 1
38+
fi
39+
40+
# ── Try to add mismatched service to group ──
41+
echo "Attempting to add ghostnet node to shadownet group (should fail)..."
42+
if om group add "$GROUP_NAME" --instance "$TEST_INSTANCE" 2>&1; then
43+
echo "ERROR: group add should have failed due to network mismatch"
44+
exit 1
45+
fi
46+
echo "Correctly rejected: network mismatch"
47+
48+
# ── Cleanup ──
49+
om group delete "$GROUP_NAME" 2>/dev/null || true
50+
51+
echo "Test passed"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Test: Group names with path traversal or invalid characters should be rejected
3+
set -euo pipefail
4+
source /tests/lib.sh
5+
6+
test_init "Group name validation"
7+
8+
# ── Path traversal attempts ──
9+
echo "Testing path traversal in group name..."
10+
if om group create "../evil" --network shadownet --octez-version 24.1 --service-user tezos 2>&1; then
11+
echo "ERROR: Should have rejected '../evil'"
12+
om group delete "../evil" 2>/dev/null || true
13+
exit 1
14+
fi
15+
echo "Correctly rejected: ../evil"
16+
17+
if om group create "foo/bar" --network shadownet --octez-version 24.1 --service-user tezos 2>&1; then
18+
echo "ERROR: Should have rejected 'foo/bar'"
19+
om group delete "foo/bar" 2>/dev/null || true
20+
exit 1
21+
fi
22+
echo "Correctly rejected: foo/bar"
23+
24+
# ── Empty name ──
25+
if om group create "" --network shadownet --octez-version 24.1 --service-user tezos 2>&1; then
26+
echo "ERROR: Should have rejected empty name"
27+
exit 1
28+
fi
29+
echo "Correctly rejected: empty name"
30+
31+
# ── Valid names should work ──
32+
VALID_NAME="test-valid-name_123-$$"
33+
om group create "$VALID_NAME" --network shadownet --octez-version 24.1 --service-user tezos
34+
echo "Accepted valid name: $VALID_NAME"
35+
36+
# Cleanup
37+
om group delete "$VALID_NAME" 2>/dev/null || true
38+
39+
echo "Test passed"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# Test: Group delete with --cascade and --ungroup flags, and mutual exclusion
3+
set -euo pipefail
4+
source /tests/lib.sh
5+
6+
test_init "Group delete cascade and ungroup"
7+
8+
GROUP_NAME="test-cascade-$$"
9+
TEST_INSTANCE="test-casc-node-$$"
10+
RPC_PORT=$(alloc_port)
11+
12+
# Pre-cleanup
13+
om group delete "$GROUP_NAME" 2>/dev/null || true
14+
register_instance "$TEST_INSTANCE"
15+
16+
# ── Create group and install a service ──
17+
echo "Creating group '$GROUP_NAME'..."
18+
om group create "$GROUP_NAME" \
19+
--network shadownet \
20+
--octez-version 24.1 \
21+
--service-user tezos
22+
23+
echo "Installing node '$TEST_INSTANCE'..."
24+
om install-node \
25+
--instance "$TEST_INSTANCE" \
26+
--network shadownet \
27+
--snapshot \
28+
--snapshot-no-check \
29+
--snapshot-uri "$SANDBOX_URL/snapshot.rolling" \
30+
--rpc-addr "127.0.0.1:$RPC_PORT" \
31+
--service-user tezos \
32+
--no-enable 2>&1 || true
33+
34+
om group add "$GROUP_NAME" --instance "$TEST_INSTANCE"
35+
36+
# ── Mutual exclusion: --cascade and --ungroup together should fail ──
37+
echo "Testing --cascade --ungroup mutual exclusion..."
38+
if om group delete "$GROUP_NAME" --cascade --ungroup 2>&1; then
39+
echo "ERROR: Should have rejected --cascade --ungroup together"
40+
exit 1
41+
fi
42+
echo "Correctly rejected: --cascade --ungroup together"
43+
44+
# ── --ungroup: removes group, keeps service ──
45+
echo "Deleting group with --ungroup..."
46+
om group delete "$GROUP_NAME" --ungroup
47+
48+
# Service should still exist but without group
49+
if ! instance_exists "$TEST_INSTANCE"; then
50+
echo "ERROR: Service should survive --ungroup delete"
51+
exit 1
52+
fi
53+
echo "Service survived --ungroup delete"
54+
55+
# Group should be gone
56+
OUTPUT=$(om group list 2>&1)
57+
if echo "$OUTPUT" | grep -q "$GROUP_NAME"; then
58+
echo "ERROR: Group still exists after --ungroup delete"
59+
exit 1
60+
fi
61+
echo "Group removed after --ungroup delete"
62+
63+
echo "Test passed"

0 commit comments

Comments
 (0)