blob: 9a6e69ce27c546406d8bf32fa7679d1da185e4ce (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.fs;
import com.yahoo.vespa.hosted.node.admin.nodeagent.UserNamespace;
import com.yahoo.vespa.hosted.node.admin.nodeagent.VespaUser;
import com.yahoo.vespa.test.file.TestFileSystem;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.attribute.UserPrincipalNotFoundException;
import static com.yahoo.vespa.hosted.node.admin.task.util.fs.ContainerUserPrincipalLookupService.ContainerGroupPrincipal;
import static com.yahoo.vespa.hosted.node.admin.task.util.fs.ContainerUserPrincipalLookupService.ContainerUserPrincipal;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author valerijf
*/
class ContainerUserPrincipalLookupServiceTest {
private final UserNamespace userNamespace = new UserNamespace(10_000, 11_000);
private final VespaUser vespaUser = new VespaUser("vespa", "users", 1000, 100);
private final ContainerUserPrincipalLookupService userPrincipalLookupService =
new ContainerUserPrincipalLookupService(TestFileSystem.create().getUserPrincipalLookupService(), userNamespace, vespaUser);
@Test
public void correctly_resolves_ids() throws IOException {
ContainerUserPrincipal user = userPrincipalLookupService.lookupPrincipalByName("1000");
assertEquals("vespa", user.getName());
assertEquals("11000", user.baseFsPrincipal().getName());
assertEquals(user, userPrincipalLookupService.lookupPrincipalByName("vespa"));
ContainerGroupPrincipal group = userPrincipalLookupService.lookupPrincipalByGroupName("100");
assertEquals("users", group.getName());
assertEquals("11100", group.baseFsPrincipal().getName());
assertEquals(group, userPrincipalLookupService.lookupPrincipalByGroupName("users"));
assertThrows(UserPrincipalNotFoundException.class, () -> userPrincipalLookupService.lookupPrincipalByName("test"));
}
}
|