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" "net/http"
) )
type AuthData struct { type AuthData struct {
User string User string
Group string Group string
@ -20,7 +19,6 @@ type Authenticator interface {
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool) DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
func NewAuth(kind string) AuthManager { func NewAuth(kind string) AuthManager {
switch kind { switch kind {

View File

@ -1,9 +1,9 @@
package auth package auth
import ( import (
"encoding/base64"
"net/http" "net/http"
"strings" "strings"
"encoding/base64"
) )
type BasicAuthInfo struct { 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 return val
} }

View File

@ -13,7 +13,6 @@ func handlerAuthenticated(c *snap.Context) {
c.Reply("snap/example/simple 1.0 (authenticated)") c.Reply("snap/example/simple 1.0 (authenticated)")
} }
func mustRunServer(auth auth.Authenticator) { func mustRunServer(auth auth.Authenticator) {
srv := snap.New("127.0.0.1:9000", "./", nil) srv := snap.New("127.0.0.1:9000", "./", nil)
srv.SetDebug(true) srv.SetDebug(true)
@ -24,7 +23,6 @@ func mustRunServer(auth auth.Authenticator) {
srv.Serve() srv.Serve()
} }
func main() { func main() {
auth := auth.NewAuth("basic") auth := auth.NewAuth("basic")
auth.AddUser("admin", "admin", "password") auth.AddUser("admin", "admin", "password")

View File

@ -55,7 +55,7 @@ func (s *Server) authenticated(auth auth.Authenticator, redirect string, handle
if redirect != "" { if redirect != "" {
http.Redirect(w, r, redirect, http.StatusSeeOther) http.Redirect(w, r, redirect, http.StatusSeeOther)
} else { } else {
http.Error(w, "Not authorized", http.StatusForbidden) http.Error(w, "Not authorized", http.StatusUnauthorized)
} }
} else { } else {
c := s.makeContext(rec, w, r) c := s.makeContext(rec, w, r)

View File

@ -11,7 +11,6 @@ import (
"git.thirdmartini.com/pub/snap/auth" "git.thirdmartini.com/pub/snap/auth"
) )
var rootExpected = []byte(` var rootExpected = []byte(`
<html lang="en"> <html lang="en">
<head> <head>
@ -38,7 +37,6 @@ User: admin
</html> </html>
`) `)
func handlerRoot(c *Context) { func handlerRoot(c *Context) {
c.RenderEx("index.html", nil) c.RenderEx("index.html", nil)
} }
@ -103,7 +101,7 @@ func TestServer_BasicAuth(t *testing.T) {
req.SetBasicAuth("admin", "badpass") req.SetBasicAuth("admin", "badpass")
data, code, err = doTestRequest(t, req) data, code, err = doTestRequest(t, req)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, http.StatusForbidden, code) assert.Equal(t, http.StatusUnauthorized, code)
// Check GOOD password and context in templates // Check GOOD password and context in templates
req, err = http.NewRequest(http.MethodGet, ts.URL+"/test", nil) req, err = http.NewRequest(http.MethodGet, ts.URL+"/test", nil)