csrf/example_test.go

24 lines
488 B
Go
Raw Permalink Normal View History

2025-01-12 11:40:15 +00:00
package csrf_test
import (
"fmt"
"net/http"
"git.bivouac.wiki/use/csrf"
)
func denied(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Println("404: " + r.URL.Path)
w.WriteHeader(403)
w.Write([]byte("CSRF invalid"))
}
func ExampleCSRF() {
k := csrf.SessionRandB64(16)
c := csrf.New(k, denied)
val := c.AuthMake("alice", "/home")
c.AuthCheck("alice", "/home", val)
// can add in the httptest examples for the middleware in a bit.
}