Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasinsaurralde committed Mar 30, 2017
1 parent 8e15682 commit 8429266
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions exempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func TestExemptRegexpCall(t *testing.T) {
re := regexp.MustCompile(pattern)
hand.ExemptRegexp(re)

got_re := hand.exemptRegexps[0]
gotRe := hand.exemptRegexps[0]

if re != got_re {
if re != gotRe {
t.Errorf("The compiled pattern is not what we gave: expected %v, got %v",
re, got_re)
re, gotRe)
}

}
Expand Down
4 changes: 1 addition & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ func defaultFailureHandler(w http.ResponseWriter, r *http.Request) {
// Extracts the "sent" token from the request
// and returns an unmasked version of it
func extractToken(r *http.Request) []byte {
var sentToken string

// Prefer the header over form value
sentToken = r.Header.Get(HeaderName)
sentToken := r.Header.Get(HeaderName)

// Then POST values
if len(sentToken) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func verifyToken(realToken, sentToken []byte) bool {

if realN == tokenLength && sentN == 2*tokenLength {
return verifyMasked(realToken, sentToken)
} else {
return false
}
return false
}

// Verifies the masked token
Expand Down
4 changes: 2 additions & 2 deletions token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func TestVerifyTokenChecksLengthCorrectly(t *testing.T) {
for i := 0; i < 64; i++ {
slice := make([]byte, i)
result := verifyToken(slice, slice)
if result != false {
if result {
t.Errorf("VerifyToken should've returned false with slices of length %d", i)
}
}

slice := make([]byte, 64)
result := verifyToken(slice[:32], slice)
if result != true {
if !result {
t.Errorf("VerifyToken should've returned true on a zeroed slice of length 64")
}
}
Expand Down

0 comments on commit 8429266

Please sign in to comment.