|
14 | 14 | // limitations under the License. |
15 | 15 | //===----------------------------------------------------------------------===// |
16 | 16 |
|
| 17 | +import Containerization |
17 | 18 | import ContainerizationError |
18 | 19 | import ContainerizationExtras |
19 | 20 | import Foundation |
@@ -1196,6 +1197,152 @@ struct ParserTest { |
1196 | 1197 | } |
1197 | 1198 | } |
1198 | 1199 |
|
| 1200 | + // MARK: - Masked Paths Parser Tests |
| 1201 | + |
| 1202 | + @Test |
| 1203 | + func testMaskedPathsParserEmpty() throws { |
| 1204 | + #expect(try Parser.maskedPaths([]) == nil) |
| 1205 | + } |
| 1206 | + |
| 1207 | + @Test |
| 1208 | + func testMaskedPathsParserAppendsToDefaults() throws { |
| 1209 | + let result = try Parser.maskedPaths(["/run/secrets"]) |
| 1210 | + #expect(result == LinuxContainer.defaultMaskedPaths() + ["/run/secrets"]) |
| 1211 | + } |
| 1212 | + |
| 1213 | + @Test |
| 1214 | + func testMaskedPathsParserResetSentinelOnly() throws { |
| 1215 | + #expect(try Parser.maskedPaths(["NONE"]) == []) |
| 1216 | + } |
| 1217 | + |
| 1218 | + @Test |
| 1219 | + func testMaskedPathsParserResetSentinelThenPath() throws { |
| 1220 | + #expect(try Parser.maskedPaths(["NONE", "/run/secrets"]) == ["/run/secrets"]) |
| 1221 | + } |
| 1222 | + |
| 1223 | + @Test |
| 1224 | + func testMaskedPathsParserPathThenResetSentinel() throws { |
| 1225 | + #expect(try Parser.maskedPaths(["/run/secrets", "NONE"]) == []) |
| 1226 | + } |
| 1227 | + |
| 1228 | + @Test |
| 1229 | + func testMaskedPathsParserResetSentinelCaseInsensitive() throws { |
| 1230 | + #expect(try Parser.maskedPaths(["none"]) == []) |
| 1231 | + #expect(try Parser.maskedPaths(["None"]) == []) |
| 1232 | + } |
| 1233 | + |
| 1234 | + @Test |
| 1235 | + func testMaskedPathsParserOrderedResets() throws { |
| 1236 | + #expect(try Parser.maskedPaths(["/a", "NONE", "/b", "/c"]) == ["/b", "/c"]) |
| 1237 | + } |
| 1238 | + |
| 1239 | + @Test |
| 1240 | + func testMaskedPathsParserStripsTrailingSlash() throws { |
| 1241 | + #expect(try Parser.maskedPaths(["NONE", "/run/secrets/"]) == ["/run/secrets"]) |
| 1242 | + #expect(try Parser.maskedPaths(["NONE", "/"]) == ["/"]) |
| 1243 | + } |
| 1244 | + |
| 1245 | + @Test |
| 1246 | + func testMaskedPathsParserTrimsWhitespace() throws { |
| 1247 | + #expect(try Parser.maskedPaths(["NONE", " /run/secrets "]) == ["/run/secrets"]) |
| 1248 | + } |
| 1249 | + |
| 1250 | + @Test |
| 1251 | + func testMaskedPathsParserDedupesRepeatedValues() throws { |
| 1252 | + #expect(try Parser.maskedPaths(["NONE", "/run/secrets", "/run/secrets/", "/run/secrets"]) == ["/run/secrets"]) |
| 1253 | + } |
| 1254 | + |
| 1255 | + @Test |
| 1256 | + func testMaskedPathsParserDedupesAgainstDefaults() throws { |
| 1257 | + let defaults = LinuxContainer.defaultMaskedPaths() |
| 1258 | + #expect(try Parser.maskedPaths([defaults[0]]) == defaults) |
| 1259 | + } |
| 1260 | + |
| 1261 | + @Test |
| 1262 | + func testMaskedPathsParserRelativePath() throws { |
| 1263 | + #expect { |
| 1264 | + _ = try Parser.maskedPaths(["proc/kcore"]) |
| 1265 | + } throws: { error in |
| 1266 | + "\(error)".contains("proc/kcore") && "\(error)".contains("masked-path") |
| 1267 | + } |
| 1268 | + } |
| 1269 | + |
| 1270 | + @Test |
| 1271 | + func testMaskedPathsParserEmptyValue() throws { |
| 1272 | + #expect { |
| 1273 | + _ = try Parser.maskedPaths([""]) |
| 1274 | + } throws: { _ in |
| 1275 | + true |
| 1276 | + } |
| 1277 | + } |
| 1278 | + |
| 1279 | + // MARK: - Readonly Paths Parser Tests |
| 1280 | + |
| 1281 | + @Test |
| 1282 | + func testReadonlyPathsParserEmpty() throws { |
| 1283 | + #expect(try Parser.readonlyPaths([]) == nil) |
| 1284 | + } |
| 1285 | + |
| 1286 | + @Test |
| 1287 | + func testReadonlyPathsParserAppendsToDefaults() throws { |
| 1288 | + let result = try Parser.readonlyPaths(["/etc/config"]) |
| 1289 | + #expect(result == LinuxContainer.defaultReadonlyPaths() + ["/etc/config"]) |
| 1290 | + } |
| 1291 | + |
| 1292 | + @Test |
| 1293 | + func testReadonlyPathsParserResetSentinelOnly() throws { |
| 1294 | + #expect(try Parser.readonlyPaths(["NONE"]) == []) |
| 1295 | + } |
| 1296 | + |
| 1297 | + @Test |
| 1298 | + func testReadonlyPathsParserResetSentinelThenPath() throws { |
| 1299 | + #expect(try Parser.readonlyPaths(["NONE", "/etc/config"]) == ["/etc/config"]) |
| 1300 | + } |
| 1301 | + |
| 1302 | + @Test |
| 1303 | + func testReadonlyPathsParserPathThenResetSentinel() throws { |
| 1304 | + #expect(try Parser.readonlyPaths(["/etc/config", "NONE"]) == []) |
| 1305 | + } |
| 1306 | + |
| 1307 | + @Test |
| 1308 | + func testReadonlyPathsParserResetSentinelCaseInsensitive() throws { |
| 1309 | + #expect(try Parser.readonlyPaths(["none"]) == []) |
| 1310 | + } |
| 1311 | + |
| 1312 | + @Test |
| 1313 | + func testReadonlyPathsParserOrderedResets() throws { |
| 1314 | + #expect(try Parser.readonlyPaths(["/a", "NONE", "/b", "/c"]) == ["/b", "/c"]) |
| 1315 | + } |
| 1316 | + |
| 1317 | + @Test |
| 1318 | + func testReadonlyPathsParserStripsTrailingSlash() throws { |
| 1319 | + #expect(try Parser.readonlyPaths(["NONE", "/etc/config/"]) == ["/etc/config"]) |
| 1320 | + } |
| 1321 | + |
| 1322 | + @Test |
| 1323 | + func testReadonlyPathsParserDedupesAgainstDefaults() throws { |
| 1324 | + let defaults = LinuxContainer.defaultReadonlyPaths() |
| 1325 | + #expect(try Parser.readonlyPaths([defaults[0]]) == defaults) |
| 1326 | + } |
| 1327 | + |
| 1328 | + @Test |
| 1329 | + func testReadonlyPathsParserRelativePath() throws { |
| 1330 | + #expect { |
| 1331 | + _ = try Parser.readonlyPaths(["proc/sys"]) |
| 1332 | + } throws: { error in |
| 1333 | + "\(error)".contains("proc/sys") && "\(error)".contains("read-only-path") |
| 1334 | + } |
| 1335 | + } |
| 1336 | + |
| 1337 | + @Test |
| 1338 | + func testReadonlyPathsParserDefaultsAreDistinctFromMaskedPaths() throws { |
| 1339 | + let masked = try Parser.maskedPaths(["/shared"]) |
| 1340 | + let readonly = try Parser.readonlyPaths(["/shared"]) |
| 1341 | + #expect(masked == LinuxContainer.defaultMaskedPaths() + ["/shared"]) |
| 1342 | + #expect(readonly == LinuxContainer.defaultReadonlyPaths() + ["/shared"]) |
| 1343 | + #expect(masked != readonly) |
| 1344 | + } |
| 1345 | + |
1199 | 1346 | // MARK: - Parser.resources |
1200 | 1347 |
|
1201 | 1348 | @Test func testResourcesCustomDefaults() throws { |
|
0 commit comments