Cleanup and autobuild file

This commit is contained in:
spsobole 2021-01-18 20:23:52 -07:00
parent 2f0e142c92
commit f583b02d88
7 changed files with 48 additions and 28 deletions

View File

@ -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 {

View File

@ -1,9 +1,9 @@
package auth
import (
"encoding/base64"
"net/http"
"strings"
"encoding/base64"
)
type BasicAuthInfo struct {

27
build.yaml Normal file
View File

@ -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:

View File

@ -124,4 +124,3 @@ func (c *Context) QueryValueWithDefault(key string, def string) string {
}
return val
}

View File

@ -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")

View File

@ -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)

View File

@ -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)