Skip to content

Commit 876cb9a

Browse files
committed
Record recipient in all messaging events #5668
2 parents 0ae47f7 + b34f00b commit 876cb9a

12 files changed

Lines changed: 373 additions & 33 deletions

File tree

.claude/skills/write-e2e-test/SKILL.md

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@ Start/restart the environment (apply latest migrations, rebuild binaries):
1212
make teardown && make setup
1313
```
1414

15-
If GNU make is required in your environment, use the repo's `gmake` shim:
16-
```
17-
PATH=/tmp/gmake-bin:$PATH ./run.sh teardown
18-
PATH=/tmp/gmake-bin:$PATH ./run.sh setup
19-
```
20-
21-
`/tmp/gmake-bin` is just a local shim directory with `make` pointing to GNU Make. Create it with:
22-
```
23-
mkdir -p /tmp/gmake-bin
24-
ln -sf /usr/local/bin/gmake /tmp/gmake-bin/make
25-
```
26-
2715
If `./run.sh setup` backgrounds daemons that die when the shell exits, run setup and the target test in the same shell:
2816
```
29-
PATH=/tmp/gmake-bin:$PATH ./run.sh teardown
30-
PATH=/tmp/gmake-bin:$PATH ./run.sh setup
31-
PATH=/tmp/gmake-bin:$PATH go test ./pkg/testrunner -count 1 -v -timeout 10m -run "TestAuthflow/<folder>/<filename_without_extension>"
17+
./run.sh teardown
18+
./run.sh setup
19+
go test ./pkg/testrunner -count 1 -v -timeout 10m -run "TestAuthflow/<folder>/<filename_without_extension>"
3220
```
3321

3422
Do not assume `zsh`. Run those commands sequentially in the developer's current shell.
@@ -305,20 +293,6 @@ If the e2e environment may be stale (e.g. first run in this session, or migratio
305293
make teardown && make setup
306294
```
307295

308-
If plain `make` fails in this repo, use:
309-
310-
```
311-
PATH=/tmp/gmake-bin:$PATH ./run.sh teardown
312-
PATH=/tmp/gmake-bin:$PATH ./run.sh setup
313-
```
314-
315-
If `/tmp/gmake-bin` does not exist yet, create it first:
316-
317-
```
318-
mkdir -p /tmp/gmake-bin
319-
ln -sf /usr/local/bin/gmake /tmp/gmake-bin/make
320-
```
321-
322296
Then run the new test(s):
323297

324298
```
@@ -328,9 +302,9 @@ cd e2e && go test ./pkg/testrunner/ -count 1 -v -timeout 10m -run "TestAuthflow/
328302
If the authgear/e2e daemons are started by `./run.sh setup` and do not survive shell exit, combine setup and test in one shell:
329303

330304
```
331-
PATH=/tmp/gmake-bin:$PATH ./run.sh teardown
332-
PATH=/tmp/gmake-bin:$PATH ./run.sh setup
333-
PATH=/tmp/gmake-bin:$PATH go test ./pkg/testrunner -count 1 -v -timeout 10m -run "TestAuthflow/<folder>/<filename_without_extension>"
305+
./run.sh teardown
306+
./run.sh setup
307+
go test ./pkg/testrunner -count 1 -v -timeout 10m -run "TestAuthflow/<folder>/<filename_without_extension>"
334308
```
335309

336310
If a test fails, read the error output, fix the test file, and re-run. Do not report the tests as done until they pass.
@@ -344,7 +318,7 @@ If a test fails, read the error output, fix the test file, and re-run. Do not re
344318
5. When testing audit events, always check the JSON path includes `payload`: `data->'payload'->'...'`.
345319
6. Prefer `ORDER BY <stable_column>, created_at` over `ORDER BY created_at` alone to avoid flaky ordering.
346320
7. To focus on one test during development, pass `-run "TestAuthflow/path/to/test"` to the test command.
347-
8. After environment changes, run `make teardown && make setup` to apply latest migrations. If `make` is broken in the current environment, use the `gmake` shim via `PATH=/tmp/gmake-bin:$PATH`.
321+
8. After environment changes, run `make teardown && make setup` to apply latest migrations.
348322
9. Always write JSON values in `input`, `output`, `query_output`, and `audit_query_output` as multi-line for readability. Prefer:
349323
```yaml
350324
input: |
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Email suppressed event records recipient
2+
authgear.yaml:
3+
override: |
4+
authenticator:
5+
oob_otp:
6+
email:
7+
email_otp_mode: code
8+
test_mode:
9+
email:
10+
enabled: true
11+
rules:
12+
- regex: "^[email protected]$"
13+
suppressed: true
14+
authentication_flow:
15+
account_recovery_flows:
16+
- name: default
17+
steps:
18+
- type: identify
19+
one_of:
20+
- identification: email
21+
on_failure: ignore
22+
steps:
23+
- type: select_destination
24+
allowed_channels:
25+
- channel: email
26+
otp_form: code
27+
- type: verify_account_recovery_code
28+
- type: reset_password
29+
before:
30+
- type: custom_sql
31+
custom_sql:
32+
path: email_user.sql
33+
steps:
34+
- name: create account recovery flow
35+
action: create
36+
input: |
37+
{
38+
"type": "account_recovery",
39+
"name": "default"
40+
}
41+
output:
42+
result: |
43+
{
44+
"action": {
45+
"type": "identify"
46+
}
47+
}
48+
- name: identify email
49+
action: input
50+
input: |
51+
{
52+
"identification": "email",
53+
"login_id": "[email protected]"
54+
}
55+
output:
56+
result: |
57+
{
58+
"action": {
59+
"type": "select_destination"
60+
}
61+
}
62+
- name: choose email destination
63+
action: input
64+
input: |
65+
{
66+
"index": 0
67+
}
68+
output:
69+
result: |
70+
{
71+
"action": {
72+
"type": "verify_account_recovery_code",
73+
"data": {
74+
"type": "account_recovery_verify_code_data",
75+
"channel": "email",
76+
"otp_form": "code"
77+
}
78+
}
79+
}
80+
- name: verify suppressed email payload records recipient
81+
action: audit_query
82+
audit_query: |
83+
SELECT
84+
activity_type,
85+
data->'payload'->>'recipient' AS recipient
86+
FROM _audit_log
87+
WHERE app_id = '{{ .AppID }}'
88+
AND activity_type = 'email.suppressed'
89+
ORDER BY created_at, id
90+
audit_query_output:
91+
rows: |
92+
[
93+
{
94+
"activity_type": "email.suppressed",
95+
"recipient": "[email protected]"
96+
}
97+
]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{{ $user_id := (uuidv4) }}
2+
{{ $email_id := (uuidv4) }}
3+
4+
INSERT INTO _auth_user (
5+
"id",
6+
"app_id",
7+
"created_at",
8+
"updated_at",
9+
"is_disabled",
10+
"standard_attributes"
11+
) VALUES (
12+
'{{ $user_id }}',
13+
'{{ .AppID }}',
14+
NOW(),
15+
NOW(),
16+
FALSE,
17+
'{"email": "[email protected]"}'
18+
);
19+
20+
INSERT INTO _auth_identity (
21+
"id",
22+
"app_id",
23+
"type",
24+
"user_id",
25+
"created_at",
26+
"updated_at"
27+
) VALUES (
28+
'{{ $email_id }}',
29+
'{{ .AppID }}',
30+
'login_id',
31+
'{{ $user_id }}',
32+
NOW(),
33+
NOW()
34+
);
35+
36+
INSERT INTO _auth_identity_login_id (
37+
"id",
38+
"app_id",
39+
"login_id_key",
40+
"login_id",
41+
"claims",
42+
"original_login_id",
43+
"unique_key",
44+
"login_id_type"
45+
) VALUES (
46+
'{{ $email_id }}',
47+
'{{ .AppID }}',
48+
'email',
49+
50+
'{"email": "[email protected]"}',
51+
52+
53+
'email'
54+
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: SMS suppressed event records recipient
2+
authgear.yaml:
3+
override: |
4+
authenticator:
5+
oob_otp:
6+
sms:
7+
phone_otp_mode: sms
8+
test_mode:
9+
sms:
10+
enabled: true
11+
rules:
12+
- regex: "^\\+6591230001$"
13+
suppressed: true
14+
authentication_flow:
15+
signup_flows:
16+
- name: default
17+
steps:
18+
- name: identify_phone
19+
type: identify
20+
one_of:
21+
- identification: phone
22+
- type: verify
23+
target_step: identify_phone
24+
- type: create_authenticator
25+
one_of:
26+
- authentication: primary_password
27+
steps:
28+
- name: create signup flow
29+
action: create
30+
input: |
31+
{
32+
"type": "signup",
33+
"name": "default"
34+
}
35+
output:
36+
result: |
37+
{
38+
"action": {
39+
"type": "identify"
40+
}
41+
}
42+
- name: identify phone
43+
action: input
44+
input: |
45+
{
46+
"identification": "phone",
47+
"login_id": "+6591230001"
48+
}
49+
output:
50+
result: |
51+
{
52+
"action": {
53+
"type": "verify"
54+
}
55+
}
56+
- name: verify suppressed sms payload records recipient
57+
action: audit_query
58+
audit_query: |
59+
SELECT
60+
activity_type,
61+
data->'payload'->>'recipient' AS recipient
62+
FROM _audit_log
63+
WHERE app_id = '{{ .AppID }}'
64+
AND activity_type = 'sms.suppressed'
65+
ORDER BY created_at, id
66+
audit_query_output:
67+
rows: |
68+
[
69+
{
70+
"activity_type": "sms.suppressed",
71+
"recipient": "+6591230001"
72+
}
73+
]

0 commit comments

Comments
 (0)