Correcting response on invalid login attempt (#2216)

Verifying detailed message error from bad login in SSO Test
This commit is contained in:
Cesar Celis Hernandez
2022-08-01 19:12:39 -04:00
committed by GitHub
parent ea0cac2a92
commit 16fd5470db
2 changed files with 20 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ package restapi
import (
"context"
"errors"
"strings"
"github.com/go-openapi/swag"
"github.com/minio/console/models"
@@ -69,6 +70,7 @@ var (
ErrDeletingEncryptionConfig = errors.New("error disabling tenant encryption")
ErrEncryptionConfigNotFound = errors.New("encryption configuration not found")
ErrPolicyNotFound = errors.New("policy does not exist")
ErrLoginNotAllowed = errors.New("login not allowed")
)
// ErrorWithContext :
@@ -93,6 +95,10 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error {
errorCode = 401
errorMessage = ErrInvalidLogin.Error()
}
if strings.Contains(err1.Error(), ErrLoginNotAllowed.Error()) {
errorCode = 400
errorMessage = ErrLoginNotAllowed.Error()
}
// console invalid erasure coding value
if errors.Is(err1, ErrInvalidErasureCodingValue) {
errorCode = 400

View File

@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
@@ -29,6 +30,8 @@ import (
"testing"
"time"
"github.com/minio/console/models"
"github.com/go-openapi/loads"
consoleoauth2 "github.com/minio/console/pkg/auth/idp/oauth2"
"github.com/minio/console/restapi"
@@ -254,5 +257,15 @@ func TestBadLogin(t *testing.T) {
fmt.Println(response)
fmt.Println(err)
expectedError := response.Status
assert.Equal("500 Internal Server Error", expectedError)
assert.Equal("400 Bad Request", expectedError)
bodyBytes, _ := ioutil.ReadAll(response.Body)
result2 := models.Error{}
err = json.Unmarshal(bodyBytes, &result2)
if err != nil {
log.Println(err)
assert.Nil(err)
}
detailedMessage := *result2.DetailedMessage
fmt.Println(detailedMessage)
assert.Equal("expected 'code' response type - got [], login not allowed", detailedMessage)
}