github.com/hpcng/singularity@v3.1.1+incompatible/internal/pkg/util/user/identity_test.go (about)

     1  /*
     2    Copyright (c) 2018, Sylabs, Inc. All rights reserved.
     3  
     4    This software is licensed under a 3-clause BSD license.  Please
     5    consult LICENSE.md file distributed with the sources of this project regarding
     6    your rights to use or distribute this software.
     7  */
     8  
     9  package user
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/sylabs/singularity/internal/pkg/test"
    15  )
    16  
    17  func TestGetPwUID(t *testing.T) {
    18  	test.DropPrivilege(t)
    19  	defer test.ResetPrivilege(t)
    20  
    21  	user, err := GetPwUID(0)
    22  	if err != nil {
    23  		t.Fatalf("Failed to retrieve information for UID 0")
    24  	}
    25  	if user.Name != "root" {
    26  		t.Fatalf("UID 0 doesn't correspond to root user")
    27  	}
    28  }
    29  
    30  func TestGetPwNam(t *testing.T) {
    31  	test.DropPrivilege(t)
    32  	defer test.ResetPrivilege(t)
    33  
    34  	user, err := GetPwNam("root")
    35  	if err != nil {
    36  		t.Fatalf("Failed to retrieve information for root user")
    37  	}
    38  	if user.UID != 0 {
    39  		t.Fatalf("root user doesn't have UID 0")
    40  	}
    41  }
    42  
    43  func TestGetGrGID(t *testing.T) {
    44  	test.DropPrivilege(t)
    45  	defer test.ResetPrivilege(t)
    46  
    47  	group, err := GetGrGID(0)
    48  	if err != nil {
    49  		t.Fatalf("Failed to retrieve information for GID 0")
    50  	}
    51  	if group.Name != "root" {
    52  		t.Fatalf("GID 0 doesn't correspond to root group")
    53  	}
    54  }
    55  
    56  func TestGetGrNam(t *testing.T) {
    57  	test.DropPrivilege(t)
    58  	defer test.ResetPrivilege(t)
    59  
    60  	group, err := GetGrNam("root")
    61  	if err != nil {
    62  		t.Fatalf("Failed to retrieve information for root group")
    63  	}
    64  	if group.GID != 0 {
    65  		t.Fatalf("root group doesn't have GID 0")
    66  	}
    67  }