Fix failing test & check formatting (#10279)

6.19.x
Max Shaposhnik 2018-07-05 10:06:11 +03:00 committed by GitHub
parent 9fe9021330
commit 321d23cb4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View File

@ -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{}

View File

@ -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)
}

View File

@ -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"