Fix failing test & check formatting (#10279)
parent
9fe9021330
commit
321d23cb4d
|
|
@ -18,15 +18,15 @@ import (
|
|||
"regexp"
|
||||
|
||||
"fmt"
|
||||
"strings"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
TokenKind = "machine_token"
|
||||
WorkspaceIdEnv = "CHE_WORKSPACE_ID"
|
||||
BearerPrefix = "bearer "
|
||||
BearerPrefix = "bearer "
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -114,10 +114,10 @@ func (handler handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
token := req.URL.Query().Get("token")
|
||||
if token == "" {
|
||||
header := req.Header.Get("Authorization")
|
||||
if header != "" && strings.HasPrefix(strings.ToLower(header), BearerPrefix) {
|
||||
token = header[len(BearerPrefix):]
|
||||
}
|
||||
header := req.Header.Get("Authorization")
|
||||
if header != "" && strings.HasPrefix(strings.ToLower(header), BearerPrefix) {
|
||||
token = header[len(BearerPrefix):]
|
||||
}
|
||||
}
|
||||
if err := authenticate(token); err == nil {
|
||||
handler.delegate.ServeHTTP(w, req)
|
||||
|
|
@ -134,10 +134,10 @@ func (handler cachingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
|||
}
|
||||
token := req.URL.Query().Get("token")
|
||||
if token == "" {
|
||||
header := req.Header.Get("Authorization")
|
||||
if header != "" && strings.HasPrefix(strings.ToLower(header), BearerPrefix) {
|
||||
token = header[len(BearerPrefix):]
|
||||
}
|
||||
header := req.Header.Get("Authorization")
|
||||
if header != "" && strings.HasPrefix(strings.ToLower(header), BearerPrefix) {
|
||||
token = header[len(BearerPrefix):]
|
||||
}
|
||||
}
|
||||
if handler.cache.Contains(token) {
|
||||
handler.delegate.ServeHTTP(w, req)
|
||||
|
|
@ -151,7 +151,7 @@ func (handler cachingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
|||
|
||||
func authenticate(token string) error {
|
||||
if token == "" {
|
||||
return errors.New("Authentication failed because: missing authentication token")
|
||||
return errors.New("Authentication failed because: missing authentication token in 'Authorization' header or 'token' query param")
|
||||
}
|
||||
|
||||
claims := &JWTClaims{}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func TestAuthenticationFailedWhenEmptyTokenProvided(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("Expecting error when no empty token provided")
|
||||
}
|
||||
expectedError := "Authentication failed because: missing 'token' query parameter"
|
||||
expectedError := "Authentication failed because: missing authentication token in 'Authorization' header or 'token' query param"
|
||||
if err.Error() != expectedError {
|
||||
t.Fatalf("Expecting error message: '%v'", expectedError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"os"
|
||||
"errors"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
const SignatureKeyEnv = "CHE_MACHINE_AUTH_SIGNATURE__PUBLIC__KEY"
|
||||
|
|
|
|||
Loading…
Reference in New Issue