Add env var to skip captcha when regression testing

This commit is contained in:
Andrea Fazzi 2020-02-12 11:14:04 +01:00
parent 3370745bb9
commit 2be776305f
5 changed files with 24 additions and 14 deletions

View file

@ -12,6 +12,7 @@ services:
environment:
- DB_HOST=db
- DB_PORT=3306
- OEF_REGRESSION_TEST=1
volumes:
- /etc/localtime:/etc/localtime:ro
- ../../config/config.regression_test.yaml:/srv/oef/config/config.yaml

View file

@ -179,7 +179,7 @@ func NewHandlers(config *config.ConfigT, renderer map[string]renderer.Renderer,
// Captcha
r.Handle("/captcha/{img}", captcha.Server(captcha.StdWidth, captcha.StdHeight))
r.Handle("/captcha/{img}", handlers.JWTCookieMiddleware.Handler(handlers.Recover(captcha.Server(captcha.StdWidth, captcha.StdHeight))))
// Home

View file

@ -3,6 +3,7 @@ package orm
import (
"fmt"
"net/http"
"os"
"strings"
"time"
@ -179,7 +180,7 @@ func (model *School) Create(db *Database, args map[string]string, w http.Respons
return school, nil
} else {
if isSubscriber(r) {
if isSubscriber(r) && os.Getenv("OEF_REGRESSION_TEST") != "1" {
if !captcha.VerifyString(r.FormValue("CaptchaID"), r.FormValue("CaptchaSolution")) {
return nil, errors.WrongCaptcha
}

View file

@ -6,6 +6,7 @@ import (
"html/template"
"io/ioutil"
"net/url"
"os"
"reflect"
"strconv"
"strings"
@ -27,6 +28,7 @@ const (
var (
funcMap = template.FuncMap{
"env": env,
"genCaptcha": genCaptcha,
"markdown": markdown,
"version": version,
@ -74,6 +76,10 @@ var (
}
)
func env(key string) string {
return os.Getenv(key)
}
func genCaptcha() string {
return captcha.New()
}

View file

@ -22,7 +22,7 @@
{{end}}
{{if $isSubscriber}}
{{template "add_update_header" dict "update" $update "addTitle" "Iscrivi la scuola" "updateTitle" (printf "Aggiorna scuola %s" (.Data|string))}}
{{template "add_update_header" dict "update" $update "addTitle" "Iscrivi una nuova scuola" "updateTitle" (printf "Aggiorna scuola %s" (.Data|string))}}
{{else}}
{{template "add_update_header" dict "update" $update "addTitle" "Crea nuova scuola" "updateTitle" (printf "Aggiorna scuola %s" (.Data|string))}}
{{end}}
@ -100,18 +100,20 @@
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "ContestDirectorLastname") "update" $update}}
</div>
</div>
{{if ne (env "OEF_REGRESSION_TEST") "1"}}
{{if .Claims|isSubscriber}}
{{$captcha := genCaptcha}}
<div class="form-group">
<img class="border" id="captcha_img" src="/captcha/{{$captcha}}.png" alt="Immagine CAPTCHA">
<button type="button" onclick="reload()" class="btn btn-outline-success"><i class="fa fa-redo"></i></button>
</div>
<div class="form-group">
{{$options := ` { name: "CaptchaSolution",id: "school_captcha_solution",placeholder: "Inserire i numeri visualizzati nell'immagine",type: "text",required: "true"} `}}
{{template "input" dict "options" ($options|yaml)}}
<input type="hidden" name="CaptchaID" value="{{$captcha}}">
<div class="form-row justify-content-center">
<div class="col-auto">
<img class="border" id="captcha_img" src="/captcha/{{$captcha}}.png" alt="Immagine CAPTCHA">
<button type="button" onclick="reload()" class="btn btn-outline-success"><i class="fa fa-redo"></i></button>
{{$options := ` { name: "CaptchaSolution",id: "school_captcha_solution",placeholder: "Inserire i numeri visualizzati sopra",type: "text",required: "true"} `}}
{{template "input" dict "options" ($options|yaml)}}
<input type="hidden" name="CaptchaID" value="{{$captcha}}">
</div>
</div>
{{end}}
{{$options := ` { saveTitle: "Invia iscrizione", model: "School" } `}}
{{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}
@ -125,7 +127,7 @@
{{end}}
</form>
{{if ne (env "OEF_REGRESSION_TEST") "1"}}
<script>
function setSrcQuery(e, q) {
var src = e.src;
@ -141,6 +143,6 @@
return false;
}
</script>
{{end}}
</div>
{{ end }}