Cleanup and autobuild file
This commit is contained in:
parent
2f0e142c92
commit
f583b02d88
|
@ -4,7 +4,6 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
type AuthData struct {
|
||||
User string
|
||||
Group string
|
||||
|
@ -20,7 +19,6 @@ type Authenticator interface {
|
|||
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
func NewAuth(kind string) AuthManager {
|
||||
switch kind {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"strings"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
type BasicAuthInfo struct {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Build config for ThirdMartini go-builder
|
||||
#
|
||||
gobuild.version.required: 1.0
|
||||
gobuild.work.dir: build
|
||||
|
||||
properties:
|
||||
version: git rev-parse --short=12 HEAD
|
||||
|
||||
jobs:
|
||||
#
|
||||
# Format source code
|
||||
format:
|
||||
- name: Format source code
|
||||
type: golang
|
||||
source: git.thirdmartini.com/pub/snap/...
|
||||
options:
|
||||
flags:
|
||||
|
||||
#
|
||||
# Run some tests
|
||||
test:
|
||||
- name: Running unit tests
|
||||
type: golang
|
||||
source: git.thirdmartini.com/pub/snap/...
|
||||
options:
|
||||
flags:
|
|
@ -124,4 +124,3 @@ func (c *Context) QueryValueWithDefault(key string, def string) string {
|
|||
}
|
||||
return val
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ func handlerAuthenticated(c *snap.Context) {
|
|||
c.Reply("snap/example/simple 1.0 (authenticated)")
|
||||
}
|
||||
|
||||
|
||||
func mustRunServer(auth auth.Authenticator) {
|
||||
srv := snap.New("127.0.0.1:9000", "./", nil)
|
||||
srv.SetDebug(true)
|
||||
|
@ -24,7 +23,6 @@ func mustRunServer(auth auth.Authenticator) {
|
|||
srv.Serve()
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
auth := auth.NewAuth("basic")
|
||||
auth.AddUser("admin", "admin", "password")
|
||||
|
|
|
@ -55,7 +55,7 @@ func (s *Server) authenticated(auth auth.Authenticator, redirect string, handle
|
|||
if redirect != "" {
|
||||
http.Redirect(w, r, redirect, http.StatusSeeOther)
|
||||
} else {
|
||||
http.Error(w, "Not authorized", http.StatusForbidden)
|
||||
http.Error(w, "Not authorized", http.StatusUnauthorized)
|
||||
}
|
||||
} else {
|
||||
c := s.makeContext(rec, w, r)
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"git.thirdmartini.com/pub/snap/auth"
|
||||
)
|
||||
|
||||
|
||||
var rootExpected = []byte(`
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -38,7 +37,6 @@ User: admin
|
|||
</html>
|
||||
`)
|
||||
|
||||
|
||||
func handlerRoot(c *Context) {
|
||||
c.RenderEx("index.html", nil)
|
||||
}
|
||||
|
@ -103,7 +101,7 @@ func TestServer_BasicAuth(t *testing.T) {
|
|||
req.SetBasicAuth("admin", "badpass")
|
||||
data, code, err = doTestRequest(t, req)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusForbidden, code)
|
||||
assert.Equal(t, http.StatusUnauthorized, code)
|
||||
|
||||
// Check GOOD password and context in templates
|
||||
req, err = http.NewRequest(http.MethodGet, ts.URL+"/test", nil)
|
||||
|
|
Loading…
Reference in New Issue