Files
faas/gateway/vendor/github.com/openfaas/faas-provider/auth/credentials_test.go
Alex Ellis 701708fe0e Update faas-provider version
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-06-08 10:16:30 +01:00

65 lines
1.5 KiB
Go

// Copyright (c) OpenFaaS Author(s). All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package auth
import (
"io/ioutil"
"os"
"path"
"testing"
)
func Test_ReadFromCustomLocation_AndNames(t *testing.T) {
tmp := os.TempDir()
userWant := "admin"
ioutil.WriteFile(path.Join(tmp, "user.txt"), []byte(userWant), 0700)
passWant := "test1234"
ioutil.WriteFile(path.Join(tmp, "pass.txt"), []byte(passWant), 0700)
reader := ReadBasicAuthFromDisk{
SecretMountPath: tmp,
UserFilename: "user.txt",
PasswordFilename: "pass.txt",
}
creds, err := reader.Read()
if err != nil {
t.Errorf("can't read secrets: %s", err.Error())
}
if creds.User != userWant {
t.Errorf("user, want: %s, got %s", userWant, creds.User)
}
if creds.Password != passWant {
t.Errorf("password, want: %s, got %s", passWant, creds.Password)
}
}
func Test_ReadFromCustomLocation_DefaultNames(t *testing.T) {
tmp := os.TempDir()
userWant := "admin"
ioutil.WriteFile(path.Join(tmp, "basic-auth-user"), []byte(userWant), 0700)
passWant := "test1234"
ioutil.WriteFile(path.Join(tmp, "basic-auth-password"), []byte(passWant), 0700)
reader := ReadBasicAuthFromDisk{
SecretMountPath: tmp,
}
creds, err := reader.Read()
if err != nil {
t.Errorf("can't read secrets: %s", err.Error())
}
if creds.User != userWant {
t.Errorf("user, want: %s, got %s", userWant, creds.User)
}
if creds.Password != passWant {
t.Errorf("password, want: %s, got %s", passWant, creds.Password)
}
}