-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e8f6fe
commit 677f8ee
Showing
5 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package backend | ||
|
||
import "testing" | ||
|
||
func TestHashPassword(t *testing.T) { | ||
hash, err := HashPassword("password") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if hash == "" { | ||
t.Fatal("hash is empty") | ||
} | ||
} | ||
|
||
func TestVerifyPassword(t *testing.T) { | ||
hash, err := HashPassword("password") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !VerifyPassword("password", hash) { | ||
t.Fatal("password did not verify") | ||
} | ||
} | ||
|
||
func TestGenerateToken(t *testing.T) { | ||
token := GenerateToken() | ||
if token == "" { | ||
t.Fatal("token is empty") | ||
} | ||
} | ||
|
||
func TestHashToken(t *testing.T) { | ||
token := GenerateToken() | ||
hash := HashToken(token) | ||
if hash == "" { | ||
t.Fatal("hash is empty") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package lfs | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestReadPointer(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
content string | ||
want Pointer | ||
wantErr error | ||
wantErrp interface{} | ||
}{ | ||
{ | ||
name: "valid pointer", | ||
content: `version https://git-lfs.github.com/spec/v1 | ||
oid sha256:1234567890123456789012345678901234567890123456789012345678901234 | ||
size 1234 | ||
`, | ||
want: Pointer{ | ||
Oid: "1234567890123456789012345678901234567890123456789012345678901234", | ||
Size: 1234, | ||
}, | ||
}, | ||
{ | ||
name: "invalid prefix", | ||
content: `version https://foobar/spec/v2 | ||
oid sha256:1234567890123456789012345678901234567890123456789012345678901234 | ||
size 1234 | ||
`, | ||
wantErr: ErrMissingPrefix, | ||
}, | ||
{ | ||
name: "invalid oid", | ||
content: `version https://git-lfs.github.com/spec/v1 | ||
oid sha256:&2345a78$012345678901234567890123456789012345678901234567890123 | ||
size 1234 | ||
`, | ||
wantErr: ErrInvalidOIDFormat, | ||
}, | ||
{ | ||
name: "invalid size", | ||
content: `version https://git-lfs.github.com/spec/v1 | ||
oid sha256:1234567890123456789012345678901234567890123456789012345678901234 | ||
size abc | ||
`, | ||
wantErrp: &strconv.NumError{}, | ||
}, | ||
{ | ||
name: "invalid structure", | ||
content: `version https://git-lfs.github.com/spec/v1 | ||
`, | ||
wantErr: ErrInvalidStructure, | ||
}, | ||
{ | ||
name: "empty pointer", | ||
wantErr: ErrMissingPrefix, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
p, err := ReadPointerFromBuffer([]byte(tc.content)) | ||
if err != tc.wantErr && !errors.As(err, &tc.wantErrp) { | ||
t.Errorf("ReadPointerFromBuffer() error = %v(%T), wantErr %v(%T)", err, err, tc.wantErr, tc.wantErr) | ||
return | ||
} | ||
if err != nil { | ||
return | ||
} | ||
|
||
if err == nil { | ||
if !p.IsValid() { | ||
t.Errorf("Expected a valid pointer") | ||
return | ||
} | ||
if p.Oid != strings.ReplaceAll(p.RelativePath(), "/", "") { | ||
t.Errorf("Expected oid to be the relative path without slashes") | ||
return | ||
} | ||
} | ||
|
||
if p.Oid != tc.want.Oid { | ||
t.Errorf("ReadPointerFromBuffer() oid = %v, want %v", p.Oid, tc.want.Oid) | ||
} | ||
if p.Size != tc.want.Size { | ||
t.Errorf("ReadPointerFromBuffer() size = %v, want %v", p.Size, tc.want.Size) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# vi: set ft=conf | ||
|
||
# convert crlf to lf on windows | ||
[windows] dos2unix tokens.txt | ||
|
||
# create user | ||
soft user create user1 --key "$USER1_AUTHORIZED_KEY" | ||
|
||
# generate jwt token | ||
usoft token create 'test1' | ||
stdout 'ss_.*' | ||
stderr 'Access token created' | ||
usoft token create --expires-in 1y 'test2' | ||
stdout 'ss_.*' | ||
stderr 'Access token created' | ||
usoft token create --expires-in 1ns 'test3' | ||
stdout 'ss_.*' | ||
stderr 'Access token created' | ||
|
||
# list tokens | ||
usoft token list | ||
cmp stdout tokens.txt | ||
|
||
# delete token | ||
usoft token delete 1 | ||
|
||
-- tokens.txt -- | ||
|
||
[1mID Name Expires In Created At [0m | ||
1 test1 - now | ||
2 test2 1 year from now now | ||
3 test3 expired now |