Added unit tests for auth.go

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2020-02-17 21:16:10 -08:00
parent d4a3521437
commit e320725e07
5 changed files with 22 additions and 19 deletions

View File

@ -29,9 +29,9 @@ import (
// --------- System passwd/shadow auth routine(s) -------------- // --------- System passwd/shadow auth routine(s) --------------
// Verify a password against system standard shadow file // Verify a password against system standard shadow file
// Note auxilliary fields for expiry policy are *not* inspected. // Note auxilliary fields for expiry policy are *not* inspected.
func VerifyPass(user, password string) (bool, error) { func VerifyPass(reader func(string) ([]byte, error), user, password string) (bool, error) {
passlib.UseDefaults(passlib.Defaults20180601) passlib.UseDefaults(passlib.Defaults20180601)
pwFileData, e := ioutil.ReadFile("/etc/shadow") pwFileData, e := reader("/etc/shadow")
if e != nil { if e != nil {
return false, e return false, e
} }

View File

@ -25,6 +25,9 @@ ls
stage "Build" stage "Build"
make all make all
stage "UnitTests"
go test -v .
stage "Test(Authtoken)" stage "Test(Authtoken)"
echo "Clearing test user $USER ~/.xs_id file ..." echo "Clearing test user $USER ~/.xs_id file ..."
rm -f ~/.xs_id rm -f ~/.xs_id

20
go.mod
View File

@ -7,23 +7,23 @@ require (
blitter.com/go/goutmp v1.0.2 blitter.com/go/goutmp v1.0.2
blitter.com/go/herradurakex v1.0.0 blitter.com/go/herradurakex v1.0.0
blitter.com/go/kyber v0.0.0-20200130200857-6f2021cb88d9 blitter.com/go/kyber v0.0.0-20200130200857-6f2021cb88d9
blitter.com/go/mtwist v1.0.1 blitter.com/go/mtwist v1.0.1 // indirect
blitter.com/go/newhope v0.0.0-20200130200750-192fc08a8aae blitter.com/go/newhope v0.0.0-20200130200750-192fc08a8aae
github.com/jameskeane/bcrypt v0.0.0-20120420032655-c3cd44c1e20f github.com/jameskeane/bcrypt v0.0.0-20120420032655-c3cd44c1e20f
github.com/klauspost/cpuid v1.2.2 github.com/klauspost/cpuid v1.2.2 // indirect
github.com/klauspost/reedsolomon v1.9.3 github.com/klauspost/reedsolomon v1.9.3 // indirect
github.com/kr/pty v1.1.4 github.com/kr/pty v1.1.4
github.com/mattn/go-isatty v0.0.7 github.com/mattn/go-isatty v0.0.7
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1 // indirect
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b // indirect
github.com/tjfoc/gmsm v1.0.1 github.com/tjfoc/gmsm v1.0.1 // indirect
github.com/xtaci/kcp-go v5.4.19+incompatible github.com/xtaci/kcp-go v5.4.19+incompatible
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/sys v0.0.0-20190902133755-9109b7679e13 golang.org/x/sys v0.0.0-20190902133755-9109b7679e13
gopkg.in/hlandau/easymetric.v1 v1.0.0 gopkg.in/hlandau/easymetric.v1 v1.0.0 // indirect
gopkg.in/hlandau/measurable.v1 v1.0.1 gopkg.in/hlandau/measurable.v1 v1.0.1 // indirect
gopkg.in/hlandau/passlib.v1 v1.0.10 gopkg.in/hlandau/passlib.v1 v1.0.10
) )

12
vendor/modules.txt vendored
View File

@ -37,19 +37,19 @@ github.com/tjfoc/gmsm/sm4
github.com/xtaci/kcp-go github.com/xtaci/kcp-go
# golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d # golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
golang.org/x/crypto/blowfish golang.org/x/crypto/blowfish
golang.org/x/crypto/cast5
golang.org/x/crypto/pbkdf2 golang.org/x/crypto/pbkdf2
golang.org/x/crypto/twofish
golang.org/x/crypto/sha3
golang.org/x/crypto/cast5
golang.org/x/crypto/salsa20 golang.org/x/crypto/salsa20
golang.org/x/crypto/tea golang.org/x/crypto/tea
golang.org/x/crypto/twofish
golang.org/x/crypto/xtea golang.org/x/crypto/xtea
golang.org/x/crypto/blake2b
golang.org/x/crypto/internal/subtle
golang.org/x/crypto/salsa20/salsa
golang.org/x/crypto/argon2 golang.org/x/crypto/argon2
golang.org/x/crypto/bcrypt golang.org/x/crypto/bcrypt
golang.org/x/crypto/internal/subtle
golang.org/x/crypto/salsa20/salsa
golang.org/x/crypto/blake2b
golang.org/x/crypto/scrypt golang.org/x/crypto/scrypt
golang.org/x/crypto/sha3
# golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 # golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
golang.org/x/net/ipv4 golang.org/x/net/ipv4
golang.org/x/net/ipv6 golang.org/x/net/ipv6

View File

@ -713,7 +713,7 @@ func main() {
} else { } else {
if useSystemPasswd { if useSystemPasswd {
//var passErr error //var passErr error
valid, _ /*passErr*/ = xs.VerifyPass(string(rec.Who()), string(rec.AuthCookie(true))) valid, _ /*passErr*/ = xs.VerifyPass(ioutil.ReadFile, string(rec.Who()), string(rec.AuthCookie(true)))
} else { } else {
valid, allowedCmds = xs.AuthUserByPasswd(string(rec.Who()), string(rec.AuthCookie(true)), "/etc/xs.passwd") valid, allowedCmds = xs.AuthUserByPasswd(string(rec.Who()), string(rec.AuthCookie(true)), "/etc/xs.passwd")
} }