Commit bb9820ff authored by Lee Brown's avatar Lee Brown

moved auth from user package and added timezone to context values

parent fad08013
......@@ -2,15 +2,14 @@ package handlers
import (
"context"
"fmt"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"net/http"
"strconv"
"geeks-accelerator/oss/saas-starter-kit/internal/account"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"gopkg.in/go-playground/validator.v9"
......@@ -42,25 +41,25 @@ func (a *Account) Read(ctx context.Context, w http.ResponseWriter, r *http.Reque
return errors.New("claims missing from context")
}
// Handle included-archived query value if set.
// Handle include-archived query value if set.
var includeArchived bool
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
includeArchived = b
}
res, err := account.Read(ctx, claims, a.MasterDB, params["id"], includeArchived)
res, err := account.Read(ctx, claims, a.MasterDB, account.AccountReadRequest{
ID: params["id"],
IncludeArchived: includeArchived,
})
if err != nil {
cause := errors.Cause(err)
switch cause {
case account.ErrNotFound:
fmt.Println("HERE!!!!! account.ErrNotFound")
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusNotFound))
default:
return errors.Wrapf(err, "ID: %s", params["id"])
......
......@@ -2,14 +2,14 @@ package handlers
import (
"context"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"net/http"
"strconv"
"strings"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"geeks-accelerator/oss/saas-starter-kit/internal/project"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
......@@ -35,7 +35,7 @@ type Project struct {
// @Param order query string false "Order columns separated by comma, example: created_at desc"
// @Param limit query integer false "Limit, example: 10"
// @Param offset query integer false "Offset, example: 20"
// @Param included-archived query boolean false "Included Archived, example: false"
// @Param include-archived query boolean false "Included Archived, example: false"
// @Success 200 {array} project.ProjectResponse
// @Failure 400 {object} web.ErrorResponse
// @Failure 403 {object} web.ErrorResponse
......@@ -92,13 +92,13 @@ func (p *Project) Find(ctx context.Context, w http.ResponseWriter, r *http.Reque
}
// Handle include-archive query value if set.
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
req.IncludedArchived = b
req.IncludeArchived = b
}
//if err := web.Decode(r, &req); err != nil {
......@@ -140,18 +140,21 @@ func (p *Project) Read(ctx context.Context, w http.ResponseWriter, r *http.Reque
return errors.New("claims missing from context")
}
// Handle included-archived query value if set.
// Handle include-archived query value if set.
var includeArchived bool
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
includeArchived = b
}
res, err := project.Read(ctx, claims, p.MasterDB, params["id"], includeArchived)
res, err := project.Read(ctx, claims, p.MasterDB, project.ProjectReadRequest{
ID: params["id"],
IncludeArchived: includeArchived,
})
if err != nil {
cause := errors.Cause(err)
switch cause {
......@@ -337,7 +340,8 @@ func (p *Project) Delete(ctx context.Context, w http.ResponseWriter, r *http.Req
return err
}
err = project.Delete(ctx, claims, p.MasterDB, params["id"])
err = project.Delete(ctx, claims, p.MasterDB,
project.ProjectDeleteRequest{ID: params["id"]})
if err != nil {
cause := errors.Cause(err)
switch cause {
......
package handlers
import (
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"log"
"net/http"
"os"
......@@ -10,6 +9,7 @@ import (
saasSwagger "geeks-accelerator/oss/saas-starter-kit/internal/mid/saas-swagger"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
_ "geeks-accelerator/oss/saas-starter-kit/internal/signup"
"github.com/jmoiron/sqlx"
"gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis"
......@@ -20,7 +20,7 @@ func API(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, masterDB
// Define base middlewares applied to all requests.
middlewares := []web.Middleware{
mid.Trace(), mid.Logger(log), mid.Errors(log), mid.Metrics(), mid.Panics(),
mid.Trace(), mid.Logger(log), mid.Errors(log, nil), mid.Metrics(), mid.Panics(),
}
// Append any global middlewares if they were included.
......@@ -62,7 +62,7 @@ func API(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, masterDB
}
app.Handle("GET", "/v1/user_accounts", ua.Find, mid.AuthenticateHeader(authenticator))
app.Handle("POST", "/v1/user_accounts", ua.Create, mid.AuthenticateHeader(authenticator), mid.HasRole(auth.RoleAdmin))
app.Handle("GET", "/v1/user_accounts/:id", ua.Read, mid.AuthenticateHeader(authenticator))
app.Handle("GET", "/v1/user_accounts/:user_id/:account_id", ua.Read, mid.AuthenticateHeader(authenticator))
app.Handle("PATCH", "/v1/user_accounts", ua.Update, mid.AuthenticateHeader(authenticator))
app.Handle("PATCH", "/v1/user_accounts/archive", ua.Archive, mid.AuthenticateHeader(authenticator), mid.HasRole(auth.RoleAdmin))
app.Handle("DELETE", "/v1/user_accounts", ua.Delete, mid.AuthenticateHeader(authenticator), mid.HasRole(auth.RoleAdmin))
......
......@@ -2,13 +2,13 @@ package handlers
import (
"context"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"net/http"
"geeks-accelerator/oss/saas-starter-kit/internal/account"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"geeks-accelerator/oss/saas-starter-kit/internal/signup"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
......
......@@ -2,8 +2,6 @@ package handlers
import (
"context"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"net/http"
"strconv"
"strings"
......@@ -11,7 +9,10 @@ import (
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"geeks-accelerator/oss/saas-starter-kit/internal/user"
"geeks-accelerator/oss/saas-starter-kit/internal/user_auth"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"gopkg.in/go-playground/validator.v9"
......@@ -23,7 +24,7 @@ var sessionTtl = time.Hour * 24
// User represents the User API method handler set.
type User struct {
MasterDB *sqlx.DB
TokenGenerator user.TokenGenerator
TokenGenerator user_auth.TokenGenerator
// ADD OTHER STATE LIKE THE LOGGER AND CONFIG HERE.
}
......@@ -40,7 +41,7 @@ type User struct {
// @Param order query string false "Order columns separated by comma, example: created_at desc"
// @Param limit query integer false "Limit, example: 10"
// @Param offset query integer false "Offset, example: 20"
// @Param included-archived query boolean false "Included Archived, example: false"
// @Param include-archived query boolean false "Included Archived, example: false"
// @Success 200 {array} user.UserResponse
// @Failure 400 {object} web.ErrorResponse
// @Failure 500 {object} web.ErrorResponse
......@@ -95,14 +96,14 @@ func (u *User) Find(ctx context.Context, w http.ResponseWriter, r *http.Request,
req.Limit = &ul
}
// Handle included-archived query value if set.
if v := r.URL.Query().Get("included-archived"); v != "" {
// Handle include-archived query value if set.
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
req.IncludedArchived = b
req.IncludeArchived = b
}
//if err := web.Decode(r, &req); err != nil {
......@@ -144,18 +145,21 @@ func (u *User) Read(ctx context.Context, w http.ResponseWriter, r *http.Request,
return errors.New("claims missing from context")
}
// Handle included-archived query value if set.
// Handle include-archived query value if set.
var includeArchived bool
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
includeArchived = b
}
res, err := user.Read(ctx, claims, u.MasterDB, params["id"], includeArchived)
res, err := user.Read(ctx, claims, u.MasterDB, user.UserReadRequest{
ID: params["id"],
IncludeArchived: includeArchived,
})
if err != nil {
cause := errors.Cause(err)
switch cause {
......@@ -394,7 +398,8 @@ func (u *User) Delete(ctx context.Context, w http.ResponseWriter, r *http.Reques
return err
}
err = user.Delete(ctx, claims, u.MasterDB, params["id"])
err = user.Delete(ctx, claims, u.MasterDB,
user.UserDeleteRequest{ID: params["id"]})
if err != nil {
cause := errors.Cause(err)
switch cause {
......@@ -437,11 +442,11 @@ func (u *User) SwitchAccount(ctx context.Context, w http.ResponseWriter, r *http
return err
}
tkn, err := user.SwitchAccount(ctx, u.MasterDB, u.TokenGenerator, claims, params["account_id"], sessionTtl, v.Now)
tkn, err := user_auth.SwitchAccount(ctx, u.MasterDB, u.TokenGenerator, claims, params["account_id"], sessionTtl, v.Now)
if err != nil {
cause := errors.Cause(err)
switch cause {
case user.ErrAuthenticationFailure:
case user_auth.ErrAuthenticationFailure:
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusUnauthorized))
default:
_, ok := cause.(validator.ValidationErrors)
......@@ -484,11 +489,11 @@ func (u *User) Token(ctx context.Context, w http.ResponseWriter, r *http.Request
// Optional to include scope.
scope := r.URL.Query().Get("scope")
tkn, err := user.Authenticate(ctx, u.MasterDB, u.TokenGenerator, email, pass, sessionTtl, v.Now, scope)
tkn, err := user_auth.Authenticate(ctx, u.MasterDB, u.TokenGenerator, email, pass, sessionTtl, v.Now, scope)
if err != nil {
cause := errors.Cause(err)
switch cause {
case user.ErrAuthenticationFailure:
case user_auth.ErrAuthenticationFailure:
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusUnauthorized))
default:
_, ok := cause.(validator.ValidationErrors)
......@@ -500,5 +505,30 @@ func (u *User) Token(ctx context.Context, w http.ResponseWriter, r *http.Request
}
}
accountID := r.URL.Query().Get("account_id")
if accountID != "" && accountID != tkn.AccountID {
claims, err := u.TokenGenerator.ParseClaims(tkn.AccessToken)
if err != nil {
return err
}
tkn, err = user_auth.SwitchAccount(ctx, u.MasterDB, u.TokenGenerator, claims, accountID, sessionTtl, v.Now)
if err != nil {
cause := errors.Cause(err)
switch cause {
case user_auth.ErrAuthenticationFailure:
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusUnauthorized))
default:
_, ok := cause.(validator.ValidationErrors)
if ok {
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
return errors.Wrap(err, "switch account")
}
}
}
return web.RespondJson(ctx, w, tkn, http.StatusOK)
}
......@@ -2,6 +2,10 @@ package handlers
import (
"context"
"net/http"
"strconv"
"strings"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
......@@ -10,9 +14,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"gopkg.in/go-playground/validator.v9"
"net/http"
"strconv"
"strings"
)
// UserAccount represents the UserAccount API method handler set.
......@@ -34,7 +35,7 @@ type UserAccount struct {
// @Param order query string false "Order columns separated by comma, example: created_at desc"
// @Param limit query integer false "Limit, example: 10"
// @Param offset query integer false "Offset, example: 20"
// @Param included-archived query boolean false "Included Archived, example: false"
// @Param include-archived query boolean false "Included Archived, example: false"
// @Success 200 {array} user_account.UserAccountResponse
// @Failure 400 {object} web.ErrorResponse
// @Failure 403 {object} web.ErrorResponse
......@@ -91,13 +92,13 @@ func (u *UserAccount) Find(ctx context.Context, w http.ResponseWriter, r *http.R
}
// Handle order query value if set.
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
req.IncludedArchived = b
req.IncludeArchived = b
}
//if err := web.Decode(r, &req); err != nil {
......@@ -132,25 +133,29 @@ func (u *UserAccount) Find(ctx context.Context, w http.ResponseWriter, r *http.R
// @Failure 400 {object} web.ErrorResponse
// @Failure 404 {object} web.ErrorResponse
// @Failure 500 {object} web.ErrorResponse
// @Router /user_accounts/{id} [get]
// @Router /user_accounts/{user_id}/{account_id} [get]
func (u *UserAccount) Read(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
claims, ok := ctx.Value(auth.Key).(auth.Claims)
if !ok {
return errors.New("claims missing from context")
}
// Handle included-archived query value if set.
// Handle include-archived query value if set.
var includeArchived bool
if v := r.URL.Query().Get("included-archived"); v != "" {
if v := r.URL.Query().Get("include-archived"); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
err = errors.WithMessagef(err, "unable to parse %s as boolean for included-archived param", v)
err = errors.WithMessagef(err, "unable to parse %s as boolean for include-archived param", v)
return web.RespondJsonError(ctx, w, weberror.NewError(ctx, err, http.StatusBadRequest))
}
includeArchived = b
}
res, err := user_account.Read(ctx, claims, u.MasterDB, params["id"], includeArchived)
res, err := user_account.Read(ctx, claims, u.MasterDB, user_account.UserAccountReadRequest{
UserID: params["user_id"],
AccountID: params["account_id"],
IncludeArchived: includeArchived,
})
if err != nil {
cause := errors.Cause(err)
switch cause {
......
......@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"net/http"
"testing"
......@@ -13,6 +12,7 @@ import (
"geeks-accelerator/oss/saas-starter-kit/internal/platform/auth"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/tests"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/weberror"
"github.com/pborman/uuid"
)
......@@ -152,7 +152,10 @@ func TestAccountCRUDAdmin(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("account %s not found: Entity not found", randID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("account %s not found: Entity not found", randID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -190,7 +193,10 @@ func TestAccountCRUDAdmin(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("account %s not found: Entity not found", tr.ForbiddenAccount.ID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("account %s not found: Entity not found", tr.ForbiddenAccount.ID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -366,7 +372,10 @@ func TestAccountCRUDUser(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("account %s not found: Entity not found", randID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("account %s not found: Entity not found", randID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -404,7 +413,10 @@ func TestAccountCRUDUser(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("account %s not found: Entity not found", tr.ForbiddenAccount.ID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("account %s not found: Entity not found", tr.ForbiddenAccount.ID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -445,7 +457,8 @@ func TestAccountCRUDUser(t *testing.T) {
t.Fatalf("\t%s\tDecode response body failed.", tests.Failed)
}
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Display(ctx)
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Response(ctx, false)
expected.StackTrace = actual.StackTrace
if diff := cmpDiff(t, expected, actual); diff {
t.Fatalf("\t%s\tReceived expected error.", tests.Failed)
}
......@@ -495,7 +508,8 @@ func TestAccountUpdate(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: "Field validation error",
StatusCode: http.StatusBadRequest,
Error: "Field validation error",
Fields: []weberror.FieldError{
//{Field: "status", Error: "Key: 'AccountUpdateRequest.status' Error:Field validation for 'status' failed on the 'oneof' tag"},
{
......@@ -506,6 +520,8 @@ func TestAccountUpdate(t *testing.T) {
Display: "status must be one of [active pending disabled]",
},
},
Details: actual.Details,
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......
......@@ -164,7 +164,10 @@ func TestProjectCRUDAdmin(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("project %s not found: Entity not found", randID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("project %s not found: Entity not found", randID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -203,7 +206,10 @@ func TestProjectCRUDAdmin(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("project %s not found: Entity not found", forbiddenProject.ID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("project %s not found: Entity not found", forbiddenProject.ID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -347,7 +353,8 @@ func TestProjectCRUDUser(t *testing.T) {
t.Fatalf("\t%s\tDecode response body failed.", tests.Failed)
}
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Display(ctx)
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Response(ctx, false)
expected.StackTrace = actual.StackTrace
if diff := cmpDiff(t, expected, actual); diff {
t.Fatalf("\t%s\tReceived expected error.", tests.Failed)
......@@ -422,7 +429,10 @@ func TestProjectCRUDUser(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("project %s not found: Entity not found", randID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("project %s not found: Entity not found", randID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -461,7 +471,10 @@ func TestProjectCRUDUser(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: fmt.Sprintf("project %s not found: Entity not found", forbiddenProject.ID),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: fmt.Sprintf("project %s not found: Entity not found", forbiddenProject.ID),
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -502,7 +515,8 @@ func TestProjectCRUDUser(t *testing.T) {
t.Fatalf("\t%s\tDecode response body failed.", tests.Failed)
}
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Display(ctx)
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Response(ctx, false)
expected.StackTrace = actual.StackTrace
if diff := cmpDiff(t, expected, actual); diff {
t.Fatalf("\t%s\tReceived expected error.", tests.Failed)
......@@ -540,7 +554,8 @@ func TestProjectCRUDUser(t *testing.T) {
t.Fatalf("\t%s\tDecode response body failed.", tests.Failed)
}
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Display(ctx)
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Response(ctx, false)
expected.StackTrace = actual.StackTrace
if diff := cmpDiff(t, expected, actual); diff {
t.Fatalf("\t%s\tReceived expected error.", tests.Failed)
......@@ -576,7 +591,8 @@ func TestProjectCRUDUser(t *testing.T) {
t.Fatalf("\t%s\tDecode response body failed.", tests.Failed)
}
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Display(ctx)
expected := mid.ErrorForbidden(ctx).(*weberror.Error).Response(ctx, false)
expected.StackTrace = actual.StackTrace
if diff := cmpDiff(t, expected, actual); diff {
t.Fatalf("\t%s\tReceived expected error.", tests.Failed)
......@@ -626,7 +642,9 @@ func TestProjectCreate(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: "Field validation error",
StatusCode: expectedStatus,
Details: actual.Details,
Error: "Field validation error",
Fields: []weberror.FieldError{
//{Field: "status", Error: "Key: 'ProjectCreateRequest.status' Error:Field validation for 'status' failed on the 'oneof' tag"},
{
......@@ -637,6 +655,7 @@ func TestProjectCreate(t *testing.T) {
Display: "status must be one of [active disabled]",
},
},
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -688,7 +707,9 @@ func TestProjectUpdate(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: "Field validation error",
StatusCode: expectedStatus,
Details: actual.Details,
Error: "Field validation error",
Fields: []weberror.FieldError{
//{Field: "status", Error: "Key: 'ProjectUpdateRequest.status' Error:Field validation for 'status' failed on the 'oneof' tag"},
{
......@@ -699,6 +720,7 @@ func TestProjectUpdate(t *testing.T) {
Display: "status must be one of [active disabled]",
},
},
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -752,7 +774,9 @@ func TestProjectArchive(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: "Field validation error",
StatusCode: expectedStatus,
Details: actual.Details,
Error: "Field validation error",
Fields: []weberror.FieldError{
//{Field: "id", Error: "Key: 'ProjectArchiveRequest.id' Error:Field validation for 'id' failed on the 'uuid' tag"},
{
......@@ -763,6 +787,7 @@ func TestProjectArchive(t *testing.T) {
Display: "id must be a valid UUID",
},
},
StackTrace: actual.StackTrace,
}
if diff := cmpDiff(t, expected, actual); diff {
......@@ -802,7 +827,10 @@ func TestProjectArchive(t *testing.T) {
}
expected := weberror.ErrorResponse{
Error: project.ErrForbidden.Error(),
StatusCode: expectedStatus,
Error: http.StatusText(expectedStatus),
Details: project.ErrForbidden.Error(),
StackTrace: actual.StackTrace,
}