github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/util/auth/auth_test.go (about) 1 // Copyright (c) 2018, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package auth 7 8 import ( 9 "testing" 10 11 "github.com/sylabs/singularity/internal/pkg/test" 12 ) 13 14 const ( 15 testToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.TCYt5XsITJX1CxPCT8yAV-TVkIEq_PbChOMqsLfRoPsnsgw5WEuts01mq-pQy7UJiN5mgRxD-WUcX16dUEMGlv50aqzpqh4Qktb3rk-BuQy72IFLOqV0G_zS245-kronKb78cPN25DGlcTwLtjPAYuNzVBAh4vGHSrQyHUdBBPM" 16 testTokenPath = "test_data/test_token" 17 ) 18 19 func Test_ReadToken(t *testing.T) { 20 21 test.DropPrivilege(t) 22 defer test.ResetPrivilege(t) 23 24 result, w := ReadToken("/no/such/file") 25 if result != "" { 26 t.Errorf("readToken from invalid file must give empty string") 27 } 28 29 result, w = ReadToken("test_data/test_token_toosmall") 30 if w != WarningTokenTooShort { 31 t.Errorf("readToken from file with bad (too small) token must give empty string") 32 } 33 34 result, _ = ReadToken(testTokenPath) 35 if result != testToken { 36 t.Errorf("readToken from valid file must match expected result") 37 } 38 }