rename project, add a naive test file
This commit is contained in:
parent
8179aee263
commit
cd06fc0486
14 changed files with 145 additions and 19 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
goldbug*
|
||||
static/
|
||||
templates/
|
|
@ -1,7 +1,6 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
//nilfm.cc/git/goldbug/cookie
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,10 +1,8 @@
|
|||
module nilfm.cc/git/goldbug
|
||||
module nilfm.cc/git/quartzgun
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gorilla/securecookie v1.1.1
|
||||
github.com/gorilla/sessions v1.2.1
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
|
||||
)
|
||||
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,6 +1,2 @@
|
|||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
|
||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
|
|
|
@ -2,10 +2,9 @@ package indentalUserDB
|
|||
|
||||
import (
|
||||
"time"
|
||||
"nilfm.cc/git/goldbug/cookie"
|
||||
"nilfm.cc/git/goldbug/auth"
|
||||
"nilfm.cc/git/quartzgun/cookie"
|
||||
"nilfm.cc/git/quartzgun/auth"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
//"io"
|
||||
"os"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
|
53
quartzgun_test.go
Normal file
53
quartzgun_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"html/template"
|
||||
"context"
|
||||
"nilfm.cc/git/quartzgun/router"
|
||||
"nilfm.cc/git/quartzgun/renderer"
|
||||
"nilfm.cc/git/quartzgun/indentalUserDB"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func AddContent(next http.Handler) http.Handler {
|
||||
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||
if !req.Form.Has("Content") {
|
||||
req.Form.Add("Content", "Yesssssss")
|
||||
}
|
||||
next.ServeHTTP(w, req)
|
||||
}
|
||||
return http.HandlerFunc(handlerFunc)
|
||||
}
|
||||
|
||||
func ApiSomething(next http.Handler) http.Handler {
|
||||
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||
*req = *req.WithContext(context.WithValue(req.Context(), "apiData", "something"))
|
||||
next.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(handlerFunc)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M){
|
||||
udb := indentalUserDB.CreateIndentalUserDB("testData/userDB.ndtl")
|
||||
udb.AddUser("nilix", "questing")
|
||||
sesh, _ := udb.InitiateSession("nilix", "questing")
|
||||
|
||||
fmt.Printf("%s // %s\n", sesh, sesh)
|
||||
rtr := &router.Router{
|
||||
StaticPaths: map[string]string{
|
||||
"/static": "testData/static",
|
||||
},
|
||||
Fallback: *template.Must(template.ParseFiles("testData/templates/error.html", "testData/templates/footer.html")),
|
||||
}
|
||||
|
||||
rtr.Get("/", AddContent(renderer.Template("testData/templates/test.html")))
|
||||
|
||||
rtr.Get("/json", ApiSomething(renderer.JSON("apiData")))
|
||||
|
||||
rtr.Get(`/thing/(?P<Thing>\w+)`, renderer.Template("testData/templates/paramTest.html"))
|
||||
|
||||
http.ListenAndServe(":8080", rtr)
|
||||
}
|
BIN
testData/static/face.png
Normal file
BIN
testData/static/face.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
1
testData/static/test.txt
Normal file
1
testData/static/test.txt
Normal file
|
@ -0,0 +1 @@
|
|||
blargh!
|
18
testData/templates/error.html
Normal file
18
testData/templates/error.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{ $params := (.Context).Value "params" }}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' href='/style.css'>
|
||||
<link rel='shortcut icon' href='/favicon.ico'>
|
||||
<title>test — error</title>
|
||||
</head>
|
||||
<body>
|
||||
<header><h1>{{ $params.ErrorCode }}</h1></header>
|
||||
<main>
|
||||
{{ $params.ErrorMessage }}
|
||||
</main>
|
||||
{{ template "footer" .}}
|
4
testData/templates/footer.html
Normal file
4
testData/templates/footer.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{ define "footer" }}
|
||||
</body>
|
||||
</html>
|
||||
{{ end }}
|
19
testData/templates/paramTest.html
Normal file
19
testData/templates/paramTest.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{{ $params := (.Context).Value "params" }}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' href='/style.css'>
|
||||
<link rel='shortcut icon' href='/favicon.ico'>
|
||||
<title>test — thing</title>
|
||||
</head>
|
||||
<body>
|
||||
<header><h1>nilFM</h1></header>
|
||||
<main>
|
||||
{{ $params.Thing }}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
17
testData/templates/test.html
Normal file
17
testData/templates/test.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' href='/style.css'>
|
||||
<link rel='shortcut icon' href='/favicon.ico'>
|
||||
<title>test — something</title>
|
||||
</head>
|
||||
<body>
|
||||
<header><h1>nilFM</h1></header>
|
||||
<main>
|
||||
{{ .Form.Get "Content" }}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
30
testData/userDB.ndtl
Normal file
30
testData/userDB.ndtl
Normal file
|
@ -0,0 +1,30 @@
|
|||
nilix:
|
||||
pass: $2a$10$IiB5QDloPOZWsdVioDYS.e0gaxQezuLmLIxtSiKC2z/.x1z2A0MyC
|
||||
session: YnDltzHIs#bkZa@sbKP#gNJpB#H_eU_jHeirWHYOmliJknG@KKghHinJXIJjDSbE
|
||||
loginTime: 1969-12-31 17:00:00 -0700 MST
|
||||
lastSeen: 1969-12-31 17:00:00 -0700 MST
|
||||
nilix::::::
|
||||
pass: $2a$10$.Y59TRn/.qBjT8KwleyrBePsC34EuPzrRlQr014bjEKuLoUCWDMtO
|
||||
session: eMOrLtCvjo_DTV_NqDLicJOugUALtiCIjdvPuzY@O!TOAAzunOs!jnCvCv#sQFxR
|
||||
loginTime: 0001-01-01 00:00:00 +0000 UTC
|
||||
lastSeen: 0001-01-01 00:00:00 +0000 UTC
|
||||
nilix:::::
|
||||
pass: $2a$10$9PegFcBV.M.AhpMDHeLD5OJoRp0O0Ddf5Gbne.t79gyTVffB2hC7a
|
||||
session: FFDcwx@vfauPc.buny$iBE.tcdwbfWgxgUdch_yhXuUPhAUvkOricxnHe#ZnmC_.
|
||||
loginTime: 0001-01-01 00:00:00 +0000 UTC
|
||||
lastSeen: 0001-01-01 00:00:00 +0000 UTC
|
||||
nilix:::
|
||||
pass: $2a$10$TocfVRA5fRVYOI0rXOQm7ucZgYjZvQhqSTdF2G7nvzsTJ77HPAXnm
|
||||
session: LxjHpBVLHd#ir!hgIIcrxnhQfXwxtcpsASjnT@kaEIKpJShHjlKaKxGcY.ImGRSw
|
||||
loginTime: 0001-01-01 00:00:00 +0000 UTC
|
||||
lastSeen: 0001-01-01 00:00:00 +0000 UTC
|
||||
nilix::::
|
||||
pass: $2a$10$a.SFEb.inhsTNPq9LnJVUeEBl4krZlX1GgTpbRXUX3KDQspiwFJ.G
|
||||
session: ycxbeIftKXS_ZgKdVUsJbCpeTvxPFlb$SRAj!TxpgKEKocHdMMitVU!lIrGhofnb
|
||||
loginTime: 0001-01-01 00:00:00 +0000 UTC
|
||||
lastSeen: 0001-01-01 00:00:00 +0000 UTC
|
||||
nilix::
|
||||
pass: $2a$10$Z81Ut6pKN7wtWS3EFoonzunMaohXVTNoQAdCu2OgwNn4IrkTwKnMm
|
||||
session: $DhiZZMFSuPhQfJBv_Nk#fksoOMyGxgCmmm$XLAvMhlhfpcgHuL#ElXwkrhnvTUO
|
||||
loginTime: 0001-01-01 00:00:00 +0000 UTC
|
||||
lastSeen: 0001-01-01 00:00:00 +0000 UTC
|
|
@ -1,5 +0,0 @@
|
|||
nilix:
|
||||
pass: $2a$10$.Y59TRn/.qBjT8KwleyrBePsC34EuPzrRlQr014bjEKuLoUCWDMtO
|
||||
session: eMOrLtCvjo_DTV_NqDLicJOugUALtiCIjdvPuzY@O!TOAAzunOs!jnCvCv#sQFxR
|
||||
loginTime: 1969-12-31 17:00:00 -0700 MST
|
||||
lastSeen: 1969-12-31 17:00:00 -0700 MST
|
Loading…
Reference in a new issue