Skip to content
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
7 changes: 4 additions & 3 deletions pkg/domain/app/auth/handlers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"net/http"
"time"

"golang.org/x/crypto/bcrypt"
)
Expand Down Expand Up @@ -40,7 +41,7 @@ func (service *Service) LocalPostLogin(w http.ResponseWriter, r *http.Request) *
}

// fetch the password hash from storage
user, err := service.local.storage.GetOneUserByName(payload.Username)
user, err := service.local.storage.GetOneUserByUsername(payload.Username)
if err != nil {
service.logger.Infof("client %s: login failed (bad username: %s)", r.RemoteAddr, err)
return output.JsonErrUnauthorized
Expand Down Expand Up @@ -138,7 +139,7 @@ func (service *Service) LocalChangePassword(w http.ResponseWriter, r *http.Reque
}

// fetch the password hash from storage
user, err := service.local.storage.GetOneUserByName(auth.Username)
user, err := service.local.storage.GetOneUserByUsername(auth.Username)
if err != nil {
// shouldn't be possible since header was valid
err = fmt.Errorf("client %s: password change for user '%s' failed (bad username: %s)", r.RemoteAddr, auth.UserTypeAndName(), err)
Expand Down Expand Up @@ -179,7 +180,7 @@ func (service *Service) LocalChangePassword(w http.ResponseWriter, r *http.Reque
}

// update password in storage
userId, err := service.local.storage.UpdateUserPassword(auth.Username, string(newPasswordHash))
userId, err := service.local.storage.PutUserPasswordHash(auth.Username, string(newPasswordHash), time.Now())
if err != nil {
err = fmt.Errorf("client %s: password change for user '%s' failed (storage error: %s)", r.RemoteAddr, auth.UserTypeAndName(), err)
service.logger.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/app/auth/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type localExtraFuncs struct {
// RefreshCheck for local users just queries the DB to confirm no-error
func (lef *localExtraFuncs) RefreshCheck() error {
// get user must work
_, err := lef.storageService.GetOneUserByName(lef.dbUsername)
_, err := lef.storageService.GetOneUserByUsername(lef.dbUsername)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/domain/app/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"sync"
"time"

"github.com/coreos/go-oidc/v3/oidc"
"go.uber.org/zap"
Expand Down Expand Up @@ -39,13 +40,13 @@ type User struct {
ID int
Username string
PasswordHash string
CreatedAt int
UpdatedAt int
CreatedAt time.Time
UpdatedAt time.Time
}

type Storage interface {
GetOneUserByName(username string) (User, error)
UpdateUserPassword(username string, newPasswordHash string) (userId int, err error)
GetOneUserByUsername(username string) (User, error)
PutUserPasswordHash(username string, passwordHash string, updatedAt time.Time) (userId int, err error)
}

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/accounts_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestDeleteAcmeAccount(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedGetResult)
compareAcmeAccount(t, acct, tc.expectedGetResult)
})
}
}
6 changes: 3 additions & 3 deletions pkg/storage/accounts_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGetAllAcmeAccounts(t *testing.T) {
t.Errorf("incorrect result length, expected '%d' but got '%d'", tc.expectedResultLen, len(accts))
}
if tc.testIndx <= len(accts)-1 {
CompareAcmeAccount(t, accts[tc.testIndx], tc.expectedAcctAtIndx)
compareAcmeAccount(t, accts[tc.testIndx], tc.expectedAcctAtIndx)
} else {
t.Errorf("couldnt test result at index '%d' because length of result array was only '%d'", tc.testIndx, len(accts))
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestGetOneAccountById(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedAcct)
compareAcmeAccount(t, acct, tc.expectedAcct)
})
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestGetOneAccountByName(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedAcct)
compareAcmeAccount(t, acct, tc.expectedAcct)
})
}
}
4 changes: 2 additions & 2 deletions pkg/storage/accounts_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ func TestPostNewAcmeAccount(t *testing.T) {
t.Errorf("expected post error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPostErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedNew)
compareAcmeAccount(t, acct, tc.expectedNew)

acct, err = storage.GetOneAcmeAccountByName(acct.Name)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedNew)
compareAcmeAccount(t, acct, tc.expectedNew)
})
}
}
8 changes: 4 additions & 4 deletions pkg/storage/accounts_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ func TestPutAcmeAccountUpdate(t *testing.T) {
t.Errorf("expected put error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPutErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedPutResult)
compareAcmeAccount(t, acct, tc.expectedPutResult)

acct, err = storage.GetOneAcmeAccountById(tc.getId)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedGetResult)
compareAcmeAccount(t, acct, tc.expectedGetResult)
})
}
}
Expand Down Expand Up @@ -380,14 +380,14 @@ func TestPutAcmeAccountNewKey(t *testing.T) {
t.Errorf("expected put error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPutErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedPutResult)
compareAcmeAccount(t, acct, tc.expectedPutResult)

acct, err = storage.GetOneAcmeAccountById(tc.getId)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeAccount(t, acct, tc.expectedGetResult)
compareAcmeAccount(t, acct, tc.expectedGetResult)
})
}
}
8 changes: 4 additions & 4 deletions pkg/storage/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
)

// CompareAcmeAccount compares acct to expectedAcct and throws appropriate errors for any differences
func CompareAcmeAccount(t *testing.T, acct, expectedAcct acme_accounts.Account) {
// compareAcmeAccount compares acct to expectedAcct and throws appropriate errors for any differences
func compareAcmeAccount(t *testing.T, acct, expectedAcct acme_accounts.Account) {
if acct.ID != expectedAcct.ID {
t.Errorf("acme account: id expected '%d' but got '%d'", expectedAcct.ID, acct.ID)
}
Expand All @@ -19,9 +19,9 @@ func CompareAcmeAccount(t *testing.T, acct, expectedAcct acme_accounts.Account)
t.Errorf("acme account: description expected '%s' but got '%s'", expectedAcct.Description, acct.Description)
}

CompareAcmeServer(t, acct.AcmeServer, expectedAcct.AcmeServer)
compareAcmeServer(t, acct.AcmeServer, expectedAcct.AcmeServer)

CompareKey(t, acct.AccountKey, expectedAcct.AccountKey)
compareKey(t, acct.AccountKey, expectedAcct.AccountKey)

if acct.Status != expectedAcct.Status {
t.Errorf("acme account: status expected '%s' but got '%s'", expectedAcct.Status, acct.Status)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/acme_servers_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestDeleteServer(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, server, tc.expectedGetResult)
compareAcmeServer(t, server, tc.expectedGetResult)
})
}
}
6 changes: 3 additions & 3 deletions pkg/storage/acme_servers_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestGetAllAcmeServers(t *testing.T) {
t.Errorf("incorrect result length, expected '%d' but got '%d'", tc.expectedResultLen, len(servers))
}
if tc.testIndx <= len(servers)-1 {
CompareAcmeServer(t, servers[tc.testIndx], tc.expectedServerAtIndx)
compareAcmeServer(t, servers[tc.testIndx], tc.expectedServerAtIndx)
} else {
t.Errorf("couldnt test result at index '%d' because length of result array was only '%d'", tc.testIndx, len(servers))
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestGetOneServerById(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, serv, tc.expectedServer)
compareAcmeServer(t, serv, tc.expectedServer)
})
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestGetOneServerByName(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, serv, tc.expectedServer)
compareAcmeServer(t, serv, tc.expectedServer)
})
}
}
4 changes: 2 additions & 2 deletions pkg/storage/acme_servers_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func TestPostNewServer(t *testing.T) {
t.Errorf("expected post error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPostErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, server, tc.expectedNew)
compareAcmeServer(t, server, tc.expectedNew)

server, err = storage.GetOneServerByName(server.Name)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, server, tc.expectedNew)
compareAcmeServer(t, server, tc.expectedNew)
})
}
}
4 changes: 2 additions & 2 deletions pkg/storage/acme_servers_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ func TestPutServerUpdate(t *testing.T) {
t.Errorf("expected put error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPutErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, server, tc.expectedPutResult)
compareAcmeServer(t, server, tc.expectedPutResult)

server, err = storage.GetOneServerById(tc.getId)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareAcmeServer(t, server, tc.expectedGetResult)
compareAcmeServer(t, server, tc.expectedGetResult)
})
}
}
4 changes: 2 additions & 2 deletions pkg/storage/acme_servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
)

// CompareAcmeServers compares server to expectedServer and throws appropriate errors for any differences
func CompareAcmeServer(t *testing.T, server, expectedServer acme_servers.Server) {
// compareAcmeServer compares server to expectedServer and throws appropriate errors for any differences
func compareAcmeServer(t *testing.T, server, expectedServer acme_servers.Server) {
if server.ID != expectedServer.ID {
t.Errorf("acme server: id expected '%d' but got '%d'", expectedServer.ID, server.ID)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/certificates_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDeleteCert(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, cert, tc.expectedGetResult)
compareCertificate(t, cert, tc.expectedGetResult)
})
}
}
6 changes: 3 additions & 3 deletions pkg/storage/certificates_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestGetAllCerts(t *testing.T) {
t.Errorf("incorrect result length, expected '%d' but got '%d'", tc.expectedResultLen, len(certs))
}
if tc.testIndx <= len(certs)-1 {
CompareCertificate(t, certs[tc.testIndx], tc.expectedAtIndx)
compareCertificate(t, certs[tc.testIndx], tc.expectedAtIndx)
} else {
t.Errorf("couldnt test result at index '%d' because length of result array was only '%d'", tc.testIndx, len(certs))
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestGetOneCertById(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, serv, tc.expectedCert)
compareCertificate(t, serv, tc.expectedCert)
})
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestGetOneCertByName(t *testing.T) {
t.Errorf("expected error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, serv, tc.expectedCert)
compareCertificate(t, serv, tc.expectedCert)
})
}
}
4 changes: 2 additions & 2 deletions pkg/storage/certificates_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ func TestPostNewCert(t *testing.T) {
t.Errorf("expected post error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPostErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, record, tc.expectedNew)
compareCertificate(t, record, tc.expectedNew)

record, err = storage.GetOneCertByName(record.Name)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, record, tc.expectedNew)
compareCertificate(t, record, tc.expectedNew)
})
}
}
14 changes: 7 additions & 7 deletions pkg/storage/certificates_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ func TestPutDetailsCert(t *testing.T) {
t.Errorf("expected put error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedPutErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, c, tc.expectedPutResult)
compareCertificate(t, c, tc.expectedPutResult)

c, err = storage.GetOneCertById(tc.getId)
if !helpers_test.ErrorsIs(err, tc.expectedGetErr) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, c, tc.expectedGetResult)
compareCertificate(t, c, tc.expectedGetResult)
})
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestPutCertApiKey(t *testing.T) {
t.Errorf("expected get cert error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, cert, tc.expectedCert)
compareCertificate(t, cert, tc.expectedCert)
})
}
}
Expand Down Expand Up @@ -562,7 +562,7 @@ func TestCertApiKeyNew(t *testing.T) {
t.Errorf("expected cert get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, cert, tc.expectedCert)
compareCertificate(t, cert, tc.expectedCert)
})
}

Expand Down Expand Up @@ -696,7 +696,7 @@ func TestPutCertUpdatedAt(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, record, tc.expectedCert)
compareCertificate(t, record, tc.expectedCert)
})
}

Expand Down Expand Up @@ -791,7 +791,7 @@ func TestPutCertClientKey(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, record, tc.expectedCert)
compareCertificate(t, record, tc.expectedCert)
})
}
}
Expand Down Expand Up @@ -924,7 +924,7 @@ func TestPutCertLastAccess(t *testing.T) {
t.Errorf("expected get error '%s' but got '%s'", helpers_test.ErrorToVal(tc.expectedGetErr), helpers_test.ErrorToVal(err))
}

CompareCertificate(t, record, tc.expectedCert)
compareCertificate(t, record, tc.expectedCert)
})
}
}
Loading