Files
ipe/vendor/github.com/goji/httpauth/basic_auth_test.go
T
claudemiro 228ed284d9 Removed godep dependency.
Golang community are discuting a vendor aproach to go dependencies. This
change will come as experimental in go 1.5. For now I am removing the
godep dependency manager and using a vendor aproach.

I still have to use the full path when importing dependencies, but when
go1.5 released I just have to rename the imports and use a -vendor
prefix when building the project.
2015-06-13 09:11:55 -03:00

45 lines
995 B
Go

package httpauth
import (
"encoding/base64"
"net/http"
"testing"
)
func TestBasicAuthAuthenticate(t *testing.T) {
// Provide a minimal test implementation.
authOpts := AuthOptions{
Realm: "Restricted",
User: "test-user",
Password: "plain-text-password",
}
b := &basicAuth{
opts: authOpts,
}
r := &http.Request{}
r.Method = "GET"
// Provide auth data, but no Authorization header
if b.authenticate(r) != false {
t.Fatal("No Authorization header supplied.")
}
// Initialise the map for HTTP headers
r.Header = http.Header(make(map[string][]string))
// Set a malformed/bad header
r.Header.Set("Authorization", " Basic")
if b.authenticate(r) != false {
t.Fatal("Malformed Authorization header supplied.")
}
// Test correct credentials
auth := base64.StdEncoding.EncodeToString([]byte(b.opts.User + ":" + b.opts.Password))
r.Header.Set("Authorization", "Basic "+auth)
if b.authenticate(r) != true {
t.Fatal("Failed on correct credentials")
}
}