internal/control/weblogin_test.go
28 lines · 950 bytes
1 symbol in this file
1package control
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/protocol"
8 "gitbay.org/gitbay/internal/store"
9)
10
11// web login over SSH counts against the same hourly bound as the
12// mailed links, since both insert into login_tokens (#278).
13func TestWebLoginSharesTheLoginLinkLimit(t *testing.T) {
14 st, _, uid := newQueueTestRepo(t)
15 for i := 0; i <= maxLoginLinksPerHour; i++ {
16 c, errOut := pruneCtx(st, t.TempDir(), store.User{ID: uid, Username: "alice"})
17 c.Cfg.Web.Mode = "accounts"
18 c.Cfg.Server.SiteURL = "https://gitbay.test"
19 c.Cfg.Limits.WriteRate = -1
20 code := Dispatch(c, []string{"web", "login"})
21 switch {
22 case i < maxLoginLinksPerHour && code != protocol.ExitOK:
23 t.Fatalf("link %d: exit %d %s", i+1, code, errOut)
24 case i == maxLoginLinksPerHour && (code != protocol.ExitDenied || !strings.Contains(errOut.String(), "login links")):
25 t.Fatalf("link %d: exit %d %q, want refused", i+1, code, errOut)
26 }
27 }
28}