mirror of https://github.com/gin-gonic/gin.git
Remove unused code (#2013)
This commit is contained in:
parent
20440b96b9
commit
5612cadb73
9
auth.go
9
auth.go
|
@ -5,7 +5,6 @@
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/subtle"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -86,11 +85,3 @@ func authorizationHeader(user, password string) string {
|
||||||
base := user + ":" + password
|
base := user + ":" + password
|
||||||
return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
|
return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
|
||||||
}
|
}
|
||||||
|
|
||||||
func secureCompare(given, actual string) bool {
|
|
||||||
if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 {
|
|
||||||
return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1
|
|
||||||
}
|
|
||||||
// Securely compare actual to itself to keep constant time, but always return false.
|
|
||||||
return subtle.ConstantTimeCompare([]byte(actual), []byte(actual)) == 1 && false
|
|
||||||
}
|
|
||||||
|
|
|
@ -81,13 +81,6 @@ func TestBasicAuthAuthorizationHeader(t *testing.T) {
|
||||||
assert.Equal(t, "Basic YWRtaW46cGFzc3dvcmQ=", authorizationHeader("admin", "password"))
|
assert.Equal(t, "Basic YWRtaW46cGFzc3dvcmQ=", authorizationHeader("admin", "password"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBasicAuthSecureCompare(t *testing.T) {
|
|
||||||
assert.True(t, secureCompare("1234567890", "1234567890"))
|
|
||||||
assert.False(t, secureCompare("123456789", "1234567890"))
|
|
||||||
assert.False(t, secureCompare("12345678900", "1234567890"))
|
|
||||||
assert.False(t, secureCompare("1234567891", "1234567890"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBasicAuthSucceed(t *testing.T) {
|
func TestBasicAuthSucceed(t *testing.T) {
|
||||||
accounts := Accounts{"admin": "password"}
|
accounts := Accounts{"admin": "password"}
|
||||||
router := New()
|
router := New()
|
||||||
|
|
Loading…
Reference in New Issue