Skip to content

Commit

Permalink
Merge 5c99096 into f11f8c8
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 committed May 29, 2019
2 parents f11f8c8 + 5c99096 commit 3278efa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions database/dbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func newDbVersion(version string) (*dbVersion, error) {
return nil, fmt.Errorf("version %s does not match the required format", version)
}
// We don't test the Atoi errors as version matches the regexp
var maj, _ = strconv.Atoi(match[0])
var min, _ = strconv.Atoi(match[1])
var maj, _ = strconv.Atoi(match[1])
var min, _ = strconv.Atoi(match[2])
return &dbVersion{
major: maj,
minor: min,
Expand Down
4 changes: 2 additions & 2 deletions database/dbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func TestDbVersion(t *testing.T) {
}

var v1, v2 *dbVersion
v1, err = newDbVersion("1.0")
v1, err = newDbVersion("1.1")
assert.Nil(t, err)

var matchTests = map[string]bool{"0.9": false, "1.0": true, "1.5": true, "2.0": true}
var matchTests = map[string]bool{"0.9": false, "1.0": false, "1.1": true, "1.5": true, "2.0": true}
for k, v := range matchTests {
v2, err = newDbVersion(k)
assert.Equal(t, v, v2.matchesRequired(v1))
Expand Down
3 changes: 1 addition & 2 deletions metrics/instrumenting.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ type ctHistogram struct {
}

func (h *ctHistogram) With(labelValues ...string) Histogram {
var histo metrics.Histogram
histo = h.Histogram.With(labelValues...)
var histo = h.Histogram.With(labelValues...)
return &ctHistogram{
Histogram: histo,
}
Expand Down
16 changes: 5 additions & 11 deletions middleware/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@ func MakeHTTPBasicAuthenticationMW(passwordToMatch string, logger cs.Logger) fun
return
}

var matched, _ = regexp.MatchString(`^[Bb]asic *`, authorizationHeader)

if !matched {
var regexpBasicAuth = `^[Bb]asic (.+)$`
var r = regexp.MustCompile(regexpBasicAuth)
var match = r.FindStringSubmatch(authorizationHeader)
if match == nil {
logger.Log("Authorization Error", "Missing basic token")
httpErrorHandler(context.TODO(), http.StatusForbidden, fmt.Errorf("Missing basic token"), w)
return
}

var splitToken = strings.Split(authorizationHeader, "Basic ")
if len(splitToken) < 2 {
splitToken = strings.Split(authorizationHeader, "basic ")
}

var accessToken = splitToken[1]

// Decode base 64
decodedToken, err := base64.StdEncoding.DecodeString(accessToken)
decodedToken, err := base64.StdEncoding.DecodeString(match[1])

if err != nil {
logger.Log("Authorization Error", "Invalid base64 token")
Expand Down

0 comments on commit 3278efa

Please sign in to comment.