test: close the gaps found by mutation checks
- api: empty names, '{' in a name, 253/254-character domains, title trimming and the name fallback
- config: an empty query or fragment in base_url
- router: leaving works on a list closed to new members
- store: an expired token is removed when presented
This commit is contained in:
parent
53ca30ad61
commit
f7ce18c3d4
4 changed files with 62 additions and 9 deletions
|
|
@ -163,6 +163,9 @@ func TestCreateListValidation(t *testing.T) {
|
|||
`{"name":".dev","domain":"example.org"}`,
|
||||
`{"name":"dev.","domain":"example.org"}`,
|
||||
`{"name":"a..b","domain":"example.org"}`,
|
||||
`{"name":"a{b","domain":"example.org"}`,
|
||||
`{"name":"","domain":"example.org","title":"Dev"}`,
|
||||
`{"name":" ","domain":"example.org","title":"Dev"}`,
|
||||
`{"name":"` + strings.Repeat("a", 31) + `","domain":"example.org"}`,
|
||||
// Domains that are not host names.
|
||||
`{"name":"dev","domain":"exa mple.org"}`,
|
||||
|
|
@ -806,3 +809,34 @@ func TestUpdateListTitleUsesTheSameRules(t *testing.T) {
|
|||
}
|
||||
expect(t, do(t, h, "PATCH", "/api/v1/lists/1", `{"title":"`+strings.Repeat("x", 200)+`"}`, true), 200)
|
||||
}
|
||||
|
||||
func TestValidDomainLengthLimits(t *testing.T) {
|
||||
l63 := strings.Repeat("a", 63)
|
||||
d253 := l63 + "." + l63 + "." + l63 + "." + strings.Repeat("a", 61)
|
||||
if len(d253) != 253 || !validDomain(d253) {
|
||||
t.Fatalf("a 253-character domain is valid (%d)", len(d253))
|
||||
}
|
||||
if validDomain(d253 + "a") {
|
||||
t.Fatal("254 characters is too long")
|
||||
}
|
||||
if !validDomain(l63+".org") || validDomain("") || validName("") {
|
||||
t.Fatal("63-character labels are valid, empty names and domains are not")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateListTrimsTheTitle(t *testing.T) {
|
||||
h := newServer(t)
|
||||
rec := do(t, h, "POST", "/api/v1/lists", `{"name":"dev","domain":"example.org","title":" Dev team \t"}`, true)
|
||||
expect(t, rec, 201)
|
||||
var l listJSON
|
||||
decode(t, rec, &l)
|
||||
if l.Title != "Dev team" {
|
||||
t.Fatalf("title = %q", l.Title)
|
||||
}
|
||||
rec = do(t, h, "POST", "/api/v1/lists", `{"name":"ops","domain":"example.org","title":" "}`, true)
|
||||
expect(t, rec, 201)
|
||||
decode(t, rec, &l)
|
||||
if l.Title != "ops" {
|
||||
t.Fatalf("a blank title falls back to the name: %q", l.Title)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,15 +262,17 @@ func TestBaseURLIsChecked(t *testing.T) {
|
|||
}
|
||||
}
|
||||
for _, bad := range []string{
|
||||
"http://lists.example.org", // RFC 8058 needs https
|
||||
"http://10.0.0.5:8081", // only loopback may use http
|
||||
"ftp://lists.example.org", // not http(s) at all
|
||||
"lists.example.org", // no scheme
|
||||
"//lists.example.org", // no scheme
|
||||
"https://", // no host
|
||||
"https:///path", // no host
|
||||
"https://lists.example.org?x=1", // query
|
||||
"https://lists.example.org/#top", // fragment
|
||||
"http://lists.example.org", // RFC 8058 needs https
|
||||
"http://10.0.0.5:8081", // only loopback may use http
|
||||
"ftp://lists.example.org", // not http(s) at all
|
||||
"lists.example.org", // no scheme
|
||||
"//lists.example.org", // no scheme
|
||||
"https://", // no host
|
||||
"https:///path", // no host
|
||||
"https://lists.example.org?x=1", // query
|
||||
"https://lists.example.org/#top",
|
||||
"https://lists.example.org/#", // an empty fragment is still one
|
||||
"https://lists.example.org/?", // an empty query is still one // fragment
|
||||
"https://user:pw@lists.example.org", // userinfo
|
||||
"https://user@lists.example.org",
|
||||
"https://lists.example.org/a b",
|
||||
|
|
|
|||
|
|
@ -571,3 +571,17 @@ func TestConfirmTokensAreUnpredictable(t *testing.T) {
|
|||
seen[tok] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Closing a list to new members must not stop a member from leaving.
|
||||
func TestLeaveConfirmationWorksOnAClosedList(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
e.command("alice@example.com", "dev+leave@example.org", nil)
|
||||
tok := token(t, lastMail(t, e.out))
|
||||
e.s.SetPolicies(e.list.ID, store.PostMembers, store.JoinClosed, store.ArchivePrivate)
|
||||
if _, err := e.command("alice@example.com", "dev+confirm-"+tok+"@example.org", nil); err != nil {
|
||||
t.Fatalf("leave on a closed list: %v", err)
|
||||
}
|
||||
if ok, _ := e.s.IsMember(e.list.ID, "alice@example.com"); ok {
|
||||
t.Fatal("alice must be gone")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -676,6 +676,9 @@ func TestConfirmPendingExpiredIsNotFound(t *testing.T) {
|
|||
if ok, _ := s.IsMember(l.ID, "dave@x.com"); ok {
|
||||
t.Fatal("an expired token must not subscribe")
|
||||
}
|
||||
if pendingRows(t, s) != 0 {
|
||||
t.Fatal("an expired token is removed when it is presented")
|
||||
}
|
||||
}
|
||||
|
||||
// Two confirmations of one token at the same time: exactly one applies.
|
||||
|
|
|
|||
Loading…
Reference in a new issue