aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2022-01-08 13:31:10 -0700
committerDerek Stevens <nilix@nilfm.cc>2022-01-08 13:31:10 -0700
commitcd06fc04864bf9c0fa9156af013bf9b6572ad76e (patch)
tree5d4f61a645b1eb9a114ac55542115c974140a9f5
parent8179aee263f4ec822716818c610fb550a278f720 (diff)
rename project, add a naive test file
-rw-r--r--.gitignore3
-rw-r--r--auth/auth.go1
-rw-r--r--go.mod4
-rw-r--r--go.sum4
-rw-r--r--indentalUserDB/indentalUserDB.go5
-rw-r--r--quartzgun_test.go53
-rw-r--r--testData/static/face.pngbin0 -> 7770 bytes
-rw-r--r--testData/static/test.txt1
-rw-r--r--testData/templates/error.html18
-rw-r--r--testData/templates/footer.html4
-rw-r--r--testData/templates/paramTest.html19
-rw-r--r--testData/templates/test.html17
-rw-r--r--testData/userDB.ndtl30
-rw-r--r--userDB.ndtl5
14 files changed, 145 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 4a468a3..e69de29 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +0,0 @@
-goldbug*
-static/
-templates/
diff --git a/auth/auth.go b/auth/auth.go
index b8ce571..b23119c 100644
--- a/auth/auth.go
+++ b/auth/auth.go
@@ -1,7 +1,6 @@
package auth
import (
- //nilfm.cc/git/goldbug/cookie
"time"
)
diff --git a/go.mod b/go.mod
index 938ef52..801ed98 100644
--- a/go.mod
+++ b/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
)
diff --git a/go.sum b/go.sum
index 28c6029..ab658c0 100644
--- a/go.sum
+++ b/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=
diff --git a/indentalUserDB/indentalUserDB.go b/indentalUserDB/indentalUserDB.go
index 588eded..08cf1ef 100644
--- a/indentalUserDB/indentalUserDB.go
+++ b/indentalUserDB/indentalUserDB.go
@@ -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"
diff --git a/quartzgun_test.go b/quartzgun_test.go
new file mode 100644
index 0000000..b21af82
--- /dev/null
+++ b/quartzgun_test.go
@@ -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)
+}
diff --git a/testData/static/face.png b/testData/static/face.png
new file mode 100644
index 0000000..d915a75
--- /dev/null
+++ b/testData/static/face.png
Binary files differ
diff --git a/testData/static/test.txt b/testData/static/test.txt
new file mode 100644
index 0000000..f6e1a57
--- /dev/null
+++ b/testData/static/test.txt
@@ -0,0 +1 @@
+blargh!
diff --git a/testData/templates/error.html b/testData/templates/error.html
new file mode 100644
index 0000000..86c502f
--- /dev/null
+++ b/testData/templates/error.html
@@ -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 &mdash; error</title>
+ </head>
+ <body>
+ <header><h1>{{ $params.ErrorCode }}</h1></header>
+ <main>
+ {{ $params.ErrorMessage }}
+ </main>
+{{ template "footer" .}}
diff --git a/testData/templates/footer.html b/testData/templates/footer.html
new file mode 100644
index 0000000..4310abf
--- /dev/null
+++ b/testData/templates/footer.html
@@ -0,0 +1,4 @@
+{{ define "footer" }}
+ </body>
+</html>
+{{ end }}
diff --git a/testData/templates/paramTest.html b/testData/templates/paramTest.html
new file mode 100644
index 0000000..d5e072e
--- /dev/null
+++ b/testData/templates/paramTest.html
@@ -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 &mdash; thing</title>
+ </head>
+ <body>
+ <header><h1>nilFM</h1></header>
+ <main>
+ {{ $params.Thing }}
+ </main>
+ </body>
+</html>
diff --git a/testData/templates/test.html b/testData/templates/test.html
new file mode 100644
index 0000000..915596d
--- /dev/null
+++ b/testData/templates/test.html
@@ -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 &mdash; something</title>
+ </head>
+ <body>
+ <header><h1>nilFM</h1></header>
+ <main>
+ {{ .Form.Get "Content" }}
+ </main>
+ </body>
+</html>
diff --git a/testData/userDB.ndtl b/testData/userDB.ndtl
new file mode 100644
index 0000000..9506698
--- /dev/null
+++ b/testData/userDB.ndtl
@@ -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
diff --git a/userDB.ndtl b/userDB.ndtl
deleted file mode 100644
index 0bf3576..0000000
--- a/userDB.ndtl
+++ /dev/null
@@ -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