Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/U Tester refactoring #187

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions database/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ func (cr *ChallengeResponse) LoadFromReader(r io.Reader) error {

// LoadString loads a PubKey from its hex-encoded string form.
func (pk *PubKey) LoadString(s string) error {
bb, err := hex.DecodeString(s)
b, err := hex.DecodeString(s)
if err != nil {
return errors.AddContext(err, ErrInvalidPublicKey.Error())
}
if len(bb) != PubKeySize {
if len(b) != PubKeySize {
return ErrInvalidPublicKey
}
*pk = bb[:]
*pk = b[:]
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func TestWithDBSession(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
17 changes: 2 additions & 15 deletions test/api/apikeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,9 @@ func testAPIKeysAcceptance(t *testing.T, at *test.AccountsTester) {
}

for _, tt := range tests {
switch tt.verb {
case http.MethodGet:
r, err = at.Request(http.MethodGet, tt.endpoint, nil, nil, nil, nil)
case http.MethodPost:
r, err = at.Request(http.MethodPost, tt.endpoint, nil, nil, nil, nil)
case http.MethodPut:
r, err = at.Request(http.MethodPut, tt.endpoint, nil, nil, nil, nil)
case http.MethodPatch:
r, err = at.Request(http.MethodPatch, tt.endpoint, nil, nil, nil, nil)
case http.MethodDelete:
r, err = at.Request(http.MethodDelete, tt.endpoint, nil, nil, nil, nil)
default:
t.Fatalf("Invalid verb: %+v", tt)
}
r, err = at.Request(tt.verb, tt.endpoint, nil, nil, nil, nil)
if err == nil || r.StatusCode != http.StatusUnauthorized || !strings.Contains(err.Error(), api.ErrAPIKeyNotAllowed.Error()) {
t.Fatalf("Expected error '%s' with status %d, got '%s' with status %d. Endpoint %s %s", api.ErrAPIKeyNotAllowed, http.StatusUnauthorized, err, r.StatusCode, tt.verb, tt.endpoint)
t.Errorf("Expected error '%s' with status %d, got '%s' with status %d. Endpoint %s %s", api.ErrAPIKeyNotAllowed, http.StatusUnauthorized, err, r.StatusCode, tt.verb, tt.endpoint)
}
}
}
4 changes: 2 additions & 2 deletions test/api/challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ func testUserAddPubKey(t *testing.T, at *test.AccountsTester) {
// Try to solve the challenge while logged in as a different user.
// NOTE: This will consume the challenge and the user will need to request
// a new one.
r, bb, err := at.UserPOST(name+"_user3@siasky.net", name+"_pass")
r, b, err := at.UserPOST(name+"_user3@siasky.net", name+"_pass")
if err != nil || r.StatusCode != http.StatusOK {
t.Fatal(r.Status, err, string(bb))
t.Fatal(r.Status, err, string(b))
}
at.SetCookie(test.ExtractCookie(r))
_, status, err = at.UserPubkeyRegisterPOST(response, ed25519.Sign(sk[:], response))
Expand Down
4 changes: 2 additions & 2 deletions test/api/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func testUploadInfo(t *testing.T, at *test.AccountsTester) {
name2 := name + "2"
email := name + "@siasky.net"
email2 := name2 + "@siasky.net"
r, _, err := at.CreateUserPost(email, name+"_pass")
r, _, err := at.UserPOST(email, name+"_pass")
if err != nil {
t.Fatal(err)
}
c1 := test.ExtractCookie(r)
r, _, err = at.CreateUserPost(email2, name2+"_pass")
r, _, err = at.UserPOST(email2, name2+"_pass")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/database/apikeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestAPIKeys(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/database/challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func TestValidateChallengeResponse(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestValidateChallengeResponse(t *testing.T) {
func TestUnconfirmedUserUpdate(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/database/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestConfiguration(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/database/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestUploadsByUser(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestUploadsByUser(t *testing.T) {
func TestUnpinUploads(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
24 changes: 12 additions & 12 deletions test/database/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func TestUserByEmail(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestUserByEmail(t *testing.T) {
func TestUserByID(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestUserByID(t *testing.T) {
func TestUserByPubKey(t *testing.T) {
ctx := context.Background()
name := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, name, nil)
db, err := test.NewDatabase(ctx, name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestUserByPubKey(t *testing.T) {
func TestUserByStripeID(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestUserByStripeID(t *testing.T) {
func TestUserBySub(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestUserBySub(t *testing.T) {
func TestUserConfirmEmail(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal("Failed to connect to the DB:", err)
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestUserConfirmEmail(t *testing.T) {
func TestUserCreate(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestUserCreateEmailConfirmation(t *testing.T) {
func TestUserDelete(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestUserDelete(t *testing.T) {
func TestUserSave(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestUserSave(t *testing.T) {
func TestUserSetStripeID(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -564,7 +564,7 @@ func TestUserPubKey(t *testing.T) {
func TestUserSetTier(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestUserSetTier(t *testing.T) {
func TestUserStats(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions test/email/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSender(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dbName := test.DBNameForTest(t.Name())
db, err := test.NewDatabase(ctx, dbName, nil)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -89,8 +89,7 @@ func TestSender(t *testing.T) {
func TestContendingSenders(t *testing.T) {
ctx := context.Background()
dbName := test.DBNameForTest(t.Name())
logger := logrus.New()
db, err := test.NewDatabase(ctx, dbName, logger)
db, err := test.NewDatabase(ctx, dbName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -123,7 +122,7 @@ func TestContendingSenders(t *testing.T) {
// messages from the DB and "send" them. It will stop doing that when it
// reaches two executions that fail to send any messages.
sender := func(serverID string) {
s, err := email.NewSender(ctx, db, logger, &test.DependencySkipSendingEmails{}, test.FauxEmailURI)
s, err := email.NewSender(ctx, db, test.NewDiscardLogger(), &test.DependencySkipSendingEmails{}, test.FauxEmailURI)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading