Skip to content

Commit d90c778

Browse files
author
Steve Ramage
committed
Test
1 parent f2d4f3c commit d90c778

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/CgroupSocketBindOptionValue.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues
22

3+
import kotlinx.html.ADDRESS
34
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
45
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*
56

@@ -15,16 +16,24 @@ class CgroupSocketBindOptionValue() : GrammarOptionValue("config_parse_cgroup_so
1516
val DASH = LiteralChoiceTerminal("-")
1617
val COLON = LiteralChoiceTerminal(":")
1718
val IP_PORT_RANGE = SequenceCombinator(IP_PORT, DASH, IP_PORT)
18-
val IP_PORTS = AlternativeCombinator(IP_PORT, IP_PORT_RANGE)
19+
val IP_PORTS = AlternativeCombinator(IP_PORT_RANGE, IP_PORT)
1920

2021
val GRAMMAR = SequenceCombinator(
2122
AlternativeCombinator(
2223
LiteralChoiceTerminal("any"),
23-
SequenceCombinator(
24-
ZeroOrOne(SequenceCombinator(ADDRESS_FAMILY, COLON)),
25-
ZeroOrOne(SequenceCombinator(TRANSPORT_PROTOCOL, COLON)),
26-
ZeroOrOne(IP_PORTS),
27-
)
24+
// The grammar has three blocks address-family, transport-protocol, and ip-ports, if there is more than one, there is a colon.
25+
// We break this up into a few cases
26+
// All specified
27+
SequenceCombinator(ADDRESS_FAMILY, COLON, TRANSPORT_PROTOCOL,COLON, IP_PORTS),
28+
// No ports
29+
SequenceCombinator(ADDRESS_FAMILY, COLON, TRANSPORT_PROTOCOL),
30+
// No transport
31+
SequenceCombinator(ADDRESS_FAMILY, COLON, IP_PORTS),
32+
// No Address family
33+
SequenceCombinator(TRANSPORT_PROTOCOL,COLON, IP_PORTS),
34+
ADDRESS_FAMILY,
35+
TRANSPORT_PROTOCOL,
36+
IP_PORTS
2837
),
2938
EOF())
3039

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/inspections/InvalidValueInspectionForCGroupSocketBind.kt

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
1111
val file = """
1212
[Service]
1313
# Allow binding IPv6 socket addresses with a port greater than or equal to 10000.
14-
SocketBindAllow=ip6:10000-65535
14+
SocketBindAllow=ipv6:10000-65535
1515
SocketBindDeny=any
1616
# Allow binding IPv4 and IPv6 socket addresses with 1234 and 4321 ports.
1717
@@ -49,12 +49,13 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
4949
assertSize(0, highlights)
5050
}
5151

52-
fun testWeakWarningWhenNineIsSpecified() {
52+
53+
fun testWeakWarningWhenInvalidAddressFamilySpecified() {
5354
// Fixture Setup
5455
// language="unit file (systemd)"
5556
val file = """
5657
[Service]
57-
BlockIOWeight=9
58+
SocketBindAllow=ipv5
5859
""".trimIndent()
5960

6061

@@ -66,17 +67,17 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
6667
// Verification
6768
assertSize(1, highlights)
6869
val info = highlights[0]
69-
assertStringContains("BlockIOWeight's value is correctly formatted but seems invalid", info!!.description)
70-
TestCase.assertEquals("9", info.text)
70+
assertStringContains("SocketBindAllow's value does not match the expected format.", info!!.description)
71+
TestCase.assertEquals("ipv5", info.text)
7172
}
7273

7374

74-
fun testWeakWarningWhenZeroIsSpecified() {
75+
fun testWeakWarningWhenInvalidTransportSpecified() {
7576
// Fixture Setup
7677
// language="unit file (systemd)"
7778
val file = """
7879
[Service]
79-
BlockIOWeight=0
80+
SocketBindAllow=icmp
8081
""".trimIndent()
8182

8283

@@ -88,16 +89,17 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
8889
// Verification
8990
assertSize(1, highlights)
9091
val info = highlights[0]
91-
assertStringContains("BlockIOWeight's value is correctly formatted but seems invalid", info!!.description)
92-
TestCase.assertEquals("0", info.text)
92+
assertStringContains("SocketBindAllow's value does not match the expected format.", info!!.description)
93+
TestCase.assertEquals("icmp", info.text)
9394
}
9495

95-
fun testWeakWarningWhenNegativeTenIsSpecified() {
96+
97+
fun testWeakWarningWhenInvalidPortSpecified() {
9698
// Fixture Setup
9799
// language="unit file (systemd)"
98100
val file = """
99101
[Service]
100-
BlockIOWeight=-10
102+
SocketBindAllow=12458757
101103
""".trimIndent()
102104

103105

@@ -109,17 +111,16 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
109111
// Verification
110112
assertSize(1, highlights)
111113
val info = highlights[0]
112-
assertStringContains("BlockIOWeight's value is correctly formatted but seems invalid", info!!.description)
113-
TestCase.assertEquals("-10", info.text)
114+
assertStringContains("SocketBindAllow's value is correctly formatted but seems invalid.", info!!.description)
115+
TestCase.assertEquals("12458757", info.text)
114116
}
115117

116-
117-
fun testWeakWarningWhenNegativeHundredThousandIsSpecified() {
118+
fun testWeakWarningWhenDoubleColonSpecified() {
118119
// Fixture Setup
119120
// language="unit file (systemd)"
120121
val file = """
121122
[Service]
122-
BlockIOWeight=-100000
123+
SocketBindAllow=ipv6::tcp
123124
""".trimIndent()
124125

125126

@@ -131,17 +132,16 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
131132
// Verification
132133
assertSize(1, highlights)
133134
val info = highlights[0]
134-
assertStringContains("BlockIOWeight's value is correctly formatted but seems invalid", info!!.description)
135-
TestCase.assertEquals("-100000", info.text)
135+
assertStringContains("SocketBindAllow's value does not match the expected format.", info!!.description)
136+
TestCase.assertEquals("::tcp", info.text)
136137
}
137138

138-
139-
fun testWeakWarningWhenOneThousandAndOneIsSpecified() {
139+
fun testWeakWarningWhenInvalidPortRangeSpecified() {
140140
// Fixture Setup
141141
// language="unit file (systemd)"
142142
val file = """
143143
[Service]
144-
BlockIOWeight=1001
144+
SocketBindAllow=ipv6:tcp:12--21485
145145
""".trimIndent()
146146

147147

@@ -153,8 +153,7 @@ class InvalidValueInspectionForCGroupSocketBindOptionValue : AbstractUnitFileTes
153153
// Verification
154154
assertSize(1, highlights)
155155
val info = highlights[0]
156-
assertStringContains("BlockIOWeight's value is correctly formatted but seems invalid", info!!.description)
157-
TestCase.assertEquals("1001", info.text)
156+
assertStringContains("SocketBindAllow's value is correctly formatted but seems invalid.", info!!.description)
157+
TestCase.assertEquals("-", info.text)
158158
}
159-
160159
}

0 commit comments

Comments
 (0)