Skip to content

Commit

Permalink
chore: add db test + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 authored and ddlees committed Jun 25, 2024
1 parent 6e0b155 commit 367e736
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 0 additions & 5 deletions cmd/api/src/api/marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ func WriteBasicResponse(ctx context.Context, inputData any, statusCode int, resp
}
}

// intended for 2xx responses such as http.StatusNoContent
func WriteEmptyResponse(_ context.Context, statusCode int, response http.ResponseWriter) {
response.WriteHeader(statusCode)
}

func WriteResponseWrapperWithPagination(ctx context.Context, data any, limit int, skip, count, statusCode int, response http.ResponseWriter) {
wrapper := ResponseWrapper{}
wrapper.Data = data
Expand Down
4 changes: 4 additions & 0 deletions cmd/api/src/database/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ func (s *BloodhoundDB) EndUserSession(ctx context.Context, userSession model.Use

// corresponding retrival function is model.UserSession.GetFlag()
func (s *BloodhoundDB) SetUserSessionFlag(ctx context.Context, userSession *model.UserSession, key model.SessionFlagKey, state bool) error {
if userSession.ID == 0 {
return errors.Error("invalid session - missing session id")
}

var auditEntry = model.AuditEntry{}
var doAudit = false
// only audit if the new state is true, meaning the EULA is currently being accepted
Expand Down
22 changes: 22 additions & 0 deletions cmd/api/src/database/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,25 @@ func TestDatabase_CreateUserSession(t *testing.T) {
assert.Equal(t, user, newUserSession.User)
}
}

func TestDatabase_SetUserSessionFlag(t *testing.T) {
var (
testCtx = context.Background()
dbInst, user = initAndCreateUser(t)
userSession = model.UserSession{
User: user,
UserID: user.ID,
ExpiresAt: time.Now().UTC().Add(time.Hour),
}
)

newUserSession, err := dbInst.CreateUserSession(testCtx, userSession)
assert.Nil(t, err)

err = dbInst.SetUserSessionFlag(testCtx, &newUserSession, model.SessionFlagFedEULAAccepted, true)
assert.Nil(t, err)

dbSess, err := dbInst.GetUserSession(testCtx, newUserSession.ID)
assert.Nil(t, err)
assert.True(t, dbSess.Flags[string(model.SessionFlagFedEULAAccepted)])
}

0 comments on commit 367e736

Please sign in to comment.