feat: Add authentication and personal user endpoint (#29)

* feat: Add authentication and personal user endpoint

This contribution adds a lot of scaffolding for the database fake
and testability of coderd.

A new endpoint "/user" is added to return the currently authenticated
user to the requester.

* Use TestMain to catch leak instead

* Add userpassword package

* Add WIP

* Add user auth

* Fix test

* Add comments

* Fix login response

* Fix order

* Fix generated code

* Update httpapi/httpapi.go

Co-authored-by: Bryan <bryan@coder.com>

Co-authored-by: Bryan <bryan@coder.com>
This commit is contained in:
Kyle Carberry
2022-01-20 13:46:51 +00:00
committed by GitHub
co-authored by Bryan
parent 36b7b20e2a
commit 6a919aea79
39 changed files with 2232 additions and 61 deletions
+5 -4
View File
@@ -5,12 +5,13 @@ import (
"net/http"
"os"
"github.com/spf13/cobra"
"golang.org/x/xerrors"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"github.com/coder/coder/coderd"
"github.com/coder/coder/database"
"github.com/spf13/cobra"
"golang.org/x/xerrors"
"github.com/coder/coder/database/databasefake"
)
func Root() *cobra.Command {
@@ -22,7 +23,7 @@ func Root() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
handler := coderd.New(&coderd.Options{
Logger: slog.Make(sloghuman.Sink(os.Stderr)),
Database: database.NewInMemory(),
Database: databasefake.New(),
})
listener, err := net.Listen("tcp", address)
+2 -1
View File
@@ -4,8 +4,9 @@ import (
"context"
"testing"
"github.com/coder/coder/coderd/cmd"
"github.com/stretchr/testify/require"
"github.com/coder/coder/coderd/cmd"
)
func TestRoot(t *testing.T) {