From 283946aa22ffeb98250db3a36fb0ce77db0813b0 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 18 Jul 2016 21:13:10 +0200 Subject: [PATCH] Return error 400 if mandatory param is missing in HTTP request --- README.md | 1 + http/http.go | 11 +++++++++-- main.go | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff04284..6c90da9 100644 --- a/README.md +++ b/README.md @@ -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. * 200 : User accept the request + * 400 : One or more mandatory parameter(s) is missing * 401 : User deny the request * 504 : User do not provide an answer (timeout) * 520 : Unknown error append diff --git a/http/http.go b/http/http.go index b8e4b52..f77c270 100644 --- a/http/http.go +++ b/http/http.go @@ -53,10 +53,17 @@ func authHandler(w http.ResponseWriter, r *http.Request) { jid := strings.Join(r.Form[PARAM_JID], "") method := strings.Join(r.Form[METHOD_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], "") timeoutStr := strings.Join(r.Form[TIMEOUTE], "") - log.Printf("%sAuth %s", LogDebug, jid) - + log.Printf("%sAuth %s", LogInfo, jid) timeout, err := strconv.Atoi(timeoutStr) if err != nil || timeout <= 0 { timeout = TimeoutSec diff --git a/main.go b/main.go index f21d676..de195ca 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) const ( - Version = "v0.2" + Version = "v0.3" configurationFilePath = "httpAuth.cfg" default_xmpp_server_address = "127.0.0.1" @@ -27,6 +27,8 @@ var ( ) func init() { + log.Printf("Running HTTP-Auth %v", Version) + err := cfg.Load(configurationFilePath, mapConfig) if err != nil { log.Fatal("Failed to load configuration file.", err)