| index 1b88244d9..4554a959d 100644 |
| --- a/internal/console/domainpoint_test.go |
| +++ b/internal/console/domainpoint_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "context" |
| "errors" |
| "io" |
| + "net" |
| "net/http" |
| "net/url" |
| "os" |
| @@ -95,6 +96,7 @@ func TestPointUnpointedDomainWritesApexAndAttaches(t *testing.T) { |
| f := newPurchaseFixture(t) |
| f.srv.cfg.DomainProof = true |
| p := f.boughtUnpointed(t) |
| + f.srv.lookupTXT = txtForPoint(f, p.Domain, "www."+p.Domain) |
| c, csrf := f.ownerBrowser(t) |
| before := setCalls(f, p.Domain) |
| status, loc, body := postForm(t, c, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {" SHOP.com "}}) |
| @@ -104,14 +106,17 @@ func TestPointUnpointedDomainWritesApexAndAttaches(t *testing.T) { |
| if n := setCalls(f, p.Domain) - before; n != 1 { |
| t.Fatalf("SetManaged calls = %d, want 1", n) |
| } |
| + if got, want := flashOf(t, f, c), "ok|"+pointMessage(domainPointCopy.Pointed, p.Domain, "kass"); got != want { |
| + t.Fatalf("flash %q, want %q", got, want) |
| + } |
| f.wantPointed(t, p.Domain) |
| f.wantClaimedBy(t, p.Domain, "kass") |
| if c := f.claim(t, p.Domain); c.CreatedBy != pointOwner(f) { |
| t.Fatalf("claim principal: %+v", c) |
| } |
| // A repeat is the same canonical set and a re-attach. |
| - if ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)); ref != nil { |
| - t.Fatalf("repeat: %+v", ref) |
| + if pending, ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)); ref != nil || pending { |
| + t.Fatalf("repeat: pending %v, %+v", pending, ref) |
| } |
| f.wantPointed(t, p.Domain) |
| f.wantClaimedBy(t, p.Domain, "kass") |
| @@ -128,7 +133,7 @@ func TestPointOtherAppsClaimRefusedNothingDetached(t *testing.T) { |
| apex, www := f.claim(t, p.Domain), f.claim(t, "www."+p.Domain) |
| |
| ctx := context.Background() |
| - ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| + _, ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| _, attachRef := f.srv.attachDomain(ctx, f.acct, "kass", p.Domain, "", "", pointOwner(f)) |
| if ref == nil || attachRef == nil || *ref != *attachRef { |
| t.Fatalf("point refusal %+v, attach door's %+v", ref, attachRef) |
| @@ -148,7 +153,7 @@ func TestPointRetryCompletesPartialAttach(t *testing.T) { |
| putPurgeClaim(t, f.rel, "zzz", "theirs", "www."+p.Domain, false) |
| |
| before := setCalls(f, p.Domain) |
| - ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| + _, ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| if ref == nil { |
| t.Fatal("the www attach was refused, but the point succeeded") |
| } |
| @@ -165,7 +170,7 @@ func TestPointRetryCompletesPartialAttach(t *testing.T) { |
| if err := f.rel.Delete(ctx, domains.ClaimKey("www."+p.Domain)); err != nil { |
| t.Fatal(err) |
| } |
| - if ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)); ref != nil { |
| + if _, ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)); ref != nil { |
| t.Fatalf("retry: %+v", ref) |
| } |
| if n := setCalls(f, p.Domain) - before; n != 2 { |
| @@ -187,7 +192,7 @@ func TestPointRefusedWhilePurchaseLive(t *testing.T) { |
| t.Fatalf("registration while registered: %+v %v", r, err) |
| } |
| before := setCalls(f, p.Domain) |
| - ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)) |
| + _, ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)) |
| if ref == nil || ref.Status != http.StatusConflict || ref.Msg != domainPointCopy.Buying { |
| t.Fatalf("refusal: %+v", ref) |
| } |
| @@ -222,7 +227,7 @@ func TestPointAfterPurgeSucceeds(t *testing.T) { |
| f.srv.trashSweep(ctx, time.Now()) |
| f.assertNoClaims(t, p.Domain) |
| |
| - if ref := f.srv.pointBoughtDomain(ctx, f.acct, "web", p.Domain, pointOwner(f)); ref != nil { |
| + if _, ref := f.srv.pointBoughtDomain(ctx, f.acct, "web", p.Domain, pointOwner(f)); ref != nil { |
| t.Fatalf("point after purge: %+v", ref) |
| } |
| f.wantPointed(t, p.Domain) |
| @@ -237,7 +242,7 @@ func TestPointNotOwnedDomainIsNeutralNotFound(t *testing.T) { |
| } |
| ctx := context.Background() |
| for _, domain := range []string{"other.com", "never.com", ""} { |
| - ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", domain, pointOwner(f)) |
| + _, ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", domain, pointOwner(f)) |
| if ref == nil || ref.Status != http.StatusNotFound { |
| t.Fatalf("%q: %+v", domain, ref) |
| } |
| @@ -407,3 +412,81 @@ func TestPointAPIPersonOwnerOnly(t *testing.T) { |
| f.wantPointed(t, p.Domain) |
| f.wantClaimedBy(t, p.Domain, "kass") |
| } |
| + |
| +// txtForPoint is a resolver that sees this account's proof at each of |
| +// hosts and nothing anywhere else. |
| +func txtForPoint(f *purchaseFixture, hosts ...string) func(context.Context, string) ([]string, error) { |
| + return func(_ context.Context, name string) ([]string, error) { |
| + for _, host := range hosts { |
| + if c := f.srv.domainChallenge(host, f.acct.Sqid); c.Name == name { |
| + return []string{c.Value}, nil |
| + } |
| + } |
| + return nil, &net.DNSError{Err: "no such host", Name: name, IsNotFound: true} |
| + } |
| +} |
| + |
| +// flashOf is the notice the console set on c, unescaped ("kind|message"). |
| +func flashOf(t *testing.T, f *purchaseFixture, c *http.Client) string { |
| + t.Helper() |
| + u, _ := url.Parse(f.ts.URL) |
| + for _, ck := range c.Jar.Cookies(u) { |
| + if ck.Name == flashCookie { |
| + v, err := url.QueryUnescape(ck.Value) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return v |
| + } |
| + } |
| + return "" |
| +} |
| + |
| +// TestPointPendingProofSaysWaiting: while either attach leaves its claim |
| +// pending (its proof is not visible yet), neither door says the domain |
| +// points at the app. Pointing again once the proofs show finishes it. |
| +func TestPointPendingProofSaysWaiting(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + f.srv.cfg.DomainProof = true |
| + p := f.boughtUnpointed(t) |
| + // The apex proof is visible, www's is not yet. |
| + f.srv.lookupTXT = txtForPoint(f, p.Domain) |
| + ctx := context.Background() |
| + |
| + pending, ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| + if ref != nil || !pending { |
| + t.Fatalf("direct: pending %v, %+v", pending, ref) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + |
| + c, csrf := f.ownerBrowser(t) |
| + status, loc, body := postForm(t, c, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {p.Domain}}) |
| + if status != http.StatusSeeOther || loc != appSettingsURL(f.acct.Sqid, "kass", "domains") { |
| + t.Fatalf("point = %d %q:\n%s", status, loc, body) |
| + } |
| + if got, want := flashOf(t, f, c), "ok|"+pointMessage(domainPointCopy.Waiting, p.Domain, "kass"); got != want { |
| + t.Fatalf("flash %q, want %q", got, want) |
| + } |
| + |
| + owner := cliToken(t, f.consoleFixture, pointOwner(f), "point-owner-api") |
| + path := "/api/cli/apps/" + f.acct.Sqid + "/kass/domains/point" |
| + status, b := buyRequest(t, f, http.MethodPost, path, owner, `{"domain":"shop.com"}`) |
| + if status != http.StatusOK || !strings.Contains(b, `"pending":true`) { |
| + t.Fatalf("api while pending: %d %s", status, b) |
| + } |
| + |
| + // Both proofs visible: the same call finishes it. |
| + f.srv.lookupTXT = txtForPoint(f, p.Domain, "www."+p.Domain) |
| + status, b = buyRequest(t, f, http.MethodPost, path, owner, `{"domain":"shop.com"}`) |
| + if status != http.StatusOK || !strings.Contains(b, `"pending":false`) { |
| + t.Fatalf("api once proven: %d %s", status, b) |
| + } |
| + status, _, body = postForm(t, c, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {p.Domain}}) |
| + if status != http.StatusSeeOther { |
| + t.Fatalf("point once proven = %d:\n%s", status, body) |
| + } |
| + if got, want := flashOf(t, f, c), "ok|"+pointMessage(domainPointCopy.Pointed, p.Domain, "kass"); got != want { |
| + t.Fatalf("flash once proven %q, want %q", got, want) |
| + } |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| +} |