Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/cli/domain_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ func printQuote(w io.Writer, q *generated.V1DomainOrderQuote) {

func printOrderResult(e *domainEnv, o *generated.V1DomainOrder) error {
if e.json {
return writeJSONTo(e.out, o)
// The order carries the card id the quote selected. It is used to
// check out and is not part of the command output.
sanitized := *o
sanitized.PaymentMethodId = nil
return writeJSONTo(e.out, &sanitized)
}
outf(e.out, "Order %s: %s\n", deref(o.Id), stateLabel(string(deref(o.State)), "DOMAIN_ORDER_STATE_"))
tw := tabwriter.NewWriter(e.out, 0, 0, 2, ' ', 0)
Expand Down
6 changes: 6 additions & 0 deletions internal/cli/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func TestDomainRegisterHappyPath(t *testing.T) {
if got := out.String(); !strings.Contains(got, "completed") || !strings.Contains(got, "example.com") || !strings.Contains(got, "succeeded") {
t.Errorf("result: %s", got)
}
if strings.Contains(out.String(), "pm-default") || strings.Contains(errOut.String(), "pm-default") {
t.Errorf("payment method id echoed: stdout %q stderr %q", out, errOut)
}
}

func TestDomainRegisterUsesGivenCard(t *testing.T) {
Expand Down Expand Up @@ -319,6 +322,9 @@ func TestDomainRegisterJSON(t *testing.T) {
if err := json.Unmarshal(out.Bytes(), &got); err != nil || got["state"] != "DOMAIN_ORDER_STATE_COMPLETED" {
t.Fatalf("json %s: %v", out, err)
}
if _, ok := got["paymentMethodId"]; ok || strings.Contains(out.String(), "pm-default") {
t.Fatalf("payment method id leaked into json: %s", out)
}
}

func TestWaitForDomainOrderTimeout(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions scripts/openapi-leak-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,36 @@ scan() {
done
}

# paymentMethodId is the registrar field the CLI sends (--card) and reads back
# so checkout charges the card the quote was priced for. In the generated
# client that word appears only as a property name: a YAML key with nothing
# after the colon, or a Go struct field whose json tag repeats the name.
# Those lines hold no card id. Any other hit — a value, an example, a comment,
# renewalPaymentMethodId, payment_method — still fails this check.
# The CLI never prints the id; see printOrderResult.
payment_method_name_only() {
local content="$1"
printf '%s\n' "${content}" | grep -qE '^[[:space:]]+paymentMethodId:[[:space:]]*$' && return 0
printf '%s\n' "${content}" | grep -qE '^[[:space:]]+PaymentMethodId[[:space:]]+\*string[[:space:]]+`json:"paymentMethodId(,omitempty)?"`[[:space:]]*$' && return 0
return 1
}

for p in "${PATTERNS[@]}"; do
hits="$(scan "${p}")"
if [[ "${p}" == '[Pp]aymentMethod|payment_method' ]]; then
kept=""
while IFS= read -r hit || [[ -n "${hit}" ]]; do
[[ -z "${hit}" ]] && continue
# scan prefixes "path:line:"; the rest is the source line.
content="${hit#*:}"
content="${content#*:}"
if payment_method_name_only "${content}"; then
continue
fi
kept+="${hit}"$'\n'
done <<<"${hits}"
hits="${kept}"
fi
if [[ -n "${hits}" ]]; then
fail "pattern ${p} found in ${GEN_DIR}:"
head -20 <<<"${hits}" >&2
Expand Down
Loading