2021-06-01 10:51:35 +02:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"dev.sum7.eu/genofire/golang-lib/web"
|
|
|
|
"dev.sum7.eu/genofire/golang-lib/web/webtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIStatus(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2021-07-14 12:29:58 +02:00
|
|
|
s, err := webtest.NewWithDBSetup(SetupMigration)
|
2021-06-28 13:59:27 +02:00
|
|
|
assert.NoError(err)
|
2021-06-25 12:22:19 +02:00
|
|
|
defer s.Close()
|
2021-06-01 10:51:35 +02:00
|
|
|
assert.NotNil(s)
|
|
|
|
|
|
|
|
hErr := web.HTTPError{}
|
|
|
|
// invalid
|
2021-06-30 15:55:34 +02:00
|
|
|
err = s.Request(http.MethodGet, "/api/v1/my/auth/status", nil, http.StatusUnauthorized, &hErr)
|
2021-06-28 12:14:20 +02:00
|
|
|
assert.NoError(err)
|
2021-06-01 10:51:35 +02:00
|
|
|
assert.Equal(APIErrorNoSession, hErr.Message)
|
|
|
|
|
2021-06-28 12:14:20 +02:00
|
|
|
err = s.TestLogin()
|
|
|
|
assert.NoError(err)
|
2021-06-01 10:51:35 +02:00
|
|
|
|
|
|
|
obj := User{}
|
|
|
|
// invalid - user
|
2021-06-30 15:55:34 +02:00
|
|
|
err = s.Request(http.MethodGet, "/api/v1/my/auth/status", nil, http.StatusOK, &obj)
|
2021-06-28 12:14:20 +02:00
|
|
|
assert.NoError(err)
|
2021-06-01 10:51:35 +02:00
|
|
|
assert.Equal("admin", obj.Username)
|
|
|
|
|
|
|
|
}
|