aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerUserPrincipalLookupServiceTest.java
blob: 525c6d9162cc7e974e34cfe077c8af3124dcd969 (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 Vespa.ai. 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.UserScope;
import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixUser;
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 freva
 */
class ContainerUserPrincipalLookupServiceTest {

    private final UserScope userScope = UserScope.create(new UserNamespace(10_000, 11_000, 10000));
    private final ContainerUserPrincipalLookupService userPrincipalLookupService =
            new ContainerUserPrincipalLookupService(TestFileSystem.create().getUserPrincipalLookupService(), userScope);

    @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("1000");
        assertEquals("vespa", group.getName());
        assertEquals("12000", group.baseFsPrincipal().getName());
        assertEquals(group, userPrincipalLookupService.lookupPrincipalByGroupName("vespa"));

        assertThrows(UserPrincipalNotFoundException.class, () -> userPrincipalLookupService.lookupPrincipalByName("test"));
    }
}