mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-03 04:38:38 -04:00
Add negative security handler tests
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
@ -11,6 +12,16 @@ type Error struct {
|
||||
ErrorString string
|
||||
}
|
||||
|
||||
func (e *Error) Read(json_str string) error {
|
||||
dec := json.NewDecoder(strings.NewReader(json_str))
|
||||
return dec.Decode(e)
|
||||
}
|
||||
|
||||
func (e *Error) Write(w http.ResponseWriter) error {
|
||||
enc := json.NewEncoder(w)
|
||||
return enc.Encode(e)
|
||||
}
|
||||
|
||||
var error_codes = map[int]string{
|
||||
1: "Not Signed In",
|
||||
2: "Unauthorized Access",
|
||||
@ -29,8 +40,7 @@ func WriteError(w http.ResponseWriter, error_code int) {
|
||||
}
|
||||
e := Error{error_code, msg}
|
||||
|
||||
enc := json.NewEncoder(w)
|
||||
err := enc.Encode(e)
|
||||
err := e.Write(w)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user