Return error 400 if mandatory param is missing in HTTP request

This commit is contained in:
Chteufleur 2016-07-18 21:13:10 +02:00
parent af21b300ea
commit 283946aa22
3 changed files with 13 additions and 3 deletions

View File

@ -51,6 +51,7 @@ GET /auth?jid=user%40host%2fresource&domain=example.org&method=POST&transaction_
This will send a request to the given JID, then return HTTP code depending on what appended. This will send a request to the given JID, then return HTTP code depending on what appended.
* 200 : User accept the request * 200 : User accept the request
* 400 : One or more mandatory parameter(s) is missing
* 401 : User deny the request * 401 : User deny the request
* 504 : User do not provide an answer (timeout) * 504 : User do not provide an answer (timeout)
* 520 : Unknown error append * 520 : Unknown error append

View File

@ -53,10 +53,17 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
jid := strings.Join(r.Form[PARAM_JID], "") jid := strings.Join(r.Form[PARAM_JID], "")
method := strings.Join(r.Form[METHOD_ACCESS], "") method := strings.Join(r.Form[METHOD_ACCESS], "")
domain := strings.Join(r.Form[DOMAIN_ACCESS], "") domain := strings.Join(r.Form[DOMAIN_ACCESS], "")
if jid == "" || method == "" || domain == "" {
// If mandatory params is missing
log.Printf("%sMandatory params is missing", LogInfo)
w.WriteHeader(http.StatusBadRequest)
return
}
transaction := strings.Join(r.Form[TRANSACTION_ID], "") transaction := strings.Join(r.Form[TRANSACTION_ID], "")
timeoutStr := strings.Join(r.Form[TIMEOUTE], "") timeoutStr := strings.Join(r.Form[TIMEOUTE], "")
log.Printf("%sAuth %s", LogDebug, jid) log.Printf("%sAuth %s", LogInfo, jid)
timeout, err := strconv.Atoi(timeoutStr) timeout, err := strconv.Atoi(timeoutStr)
if err != nil || timeout <= 0 { if err != nil || timeout <= 0 {
timeout = TimeoutSec timeout = TimeoutSec

View File

@ -15,7 +15,7 @@ import (
) )
const ( const (
Version = "v0.2" Version = "v0.3"
configurationFilePath = "httpAuth.cfg" configurationFilePath = "httpAuth.cfg"
default_xmpp_server_address = "127.0.0.1" default_xmpp_server_address = "127.0.0.1"
@ -27,6 +27,8 @@ var (
) )
func init() { func init() {
log.Printf("Running HTTP-Auth %v", Version)
err := cfg.Load(configurationFilePath, mapConfig) err := cfg.Load(configurationFilePath, mapConfig)
if err != nil { if err != nil {
log.Fatal("Failed to load configuration file.", err) log.Fatal("Failed to load configuration file.", err)