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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author jonmv
*/
public class HostNameTest {
@Test
void testNames() {
HostName.of("name-123.0.321-eman");
HostName.of(("." + "a".repeat(32)).repeat(2).substring(1, 65));
HostName.of("123");
assertThrows(IllegalArgumentException.class, () -> HostName.of("_"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("-"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("."));
assertThrows(IllegalArgumentException.class, () -> HostName.of("-foo"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo-"));
assertThrows(IllegalArgumentException.class, () -> HostName.of(".foo"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo."));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo..bar"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo.-.bar"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo/"));
assertThrows(IllegalArgumentException.class, () -> HostName.of("foo%"));
assertThrows(IllegalArgumentException.class, () -> HostName.of(("." + "a".repeat(32)).repeat(2).substring(1, 66)));
assertThrows(IllegalArgumentException.class, () -> HostName.of("a".repeat(64)));
}
}
|