File size: 9,875 Bytes
4514571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
diff --git a/test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts b/test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts
index be01f7f9a6..853fcd0d1b 100644
--- a/test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts
+++ b/test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts
@@ -1,9 +1,10 @@
 import { nextTestSetup } from 'e2e-utils'
 import { createRequestTracker } from 'e2e-utils/request-tracker'
 import { retry } from 'next-test-utils'
-import { outdent } from 'outdent'
 
 describe('unrecognized server actions', () => {
+  const unrecognizedActionId = '0'.repeat(42)
+
   const { next, isNextDeploy, isNextDev } = nextTestSetup({
     files: __dirname,
   })
@@ -36,50 +37,72 @@ describe('unrecognized server actions', () => {
       expect(res.status).toBe(404)
     })
 
-    it.each([
+    describe.each([
       {
-        // encodeReply encodes simple args as plaintext.
-        name: 'plaintext',
-        request: {
-          contentType: 'text/plain;charset=UTF-8',
-          body: '{}',
-        },
+        idType: 'malformed',
+        actionId: '123',
+        expectedClassification: 'invalid',
       },
       {
-        // encodeReply encodes complex args as FormData.
-        // this body is empty and wouldn't match how react encodes an action, but it should be rejected
-        // before we even get to parsing the FormData, so it doesn't really matter.
-        name: 'form-data/multipart',
-        request: {
-          body: new FormData(),
-        },
+        idType: 'plausible but missing',
+        actionId: unrecognizedActionId,
+        expectedClassification: 'missing',
       },
-    ])(
-      'should 404 when POSTing a server action with an unrecognized id to a nonexistent page: $name',
-      async ({ request: { contentType, body } }) => {
-        const res = await next.fetch('/non-existent-route', {
-          method: 'POST',
-          headers: {
-            'next-action': '123',
-            ...(contentType ? { 'content-type': contentType } : undefined),
+      {
+        // Object reflection names must be handled as malformed client input,
+        // rather than being resolved through Object.prototype.
+        idType: 'object reflection property name',
+        actionId: 'toString',
+        expectedClassification: 'invalid',
+      },
+    ])('with a $idType id', ({ actionId, expectedClassification }) => {
+      it.each([
+        {
+          // encodeReply encodes simple args as plaintext.
+          name: 'plaintext',
+          request: {
+            contentType: 'text/plain;charset=UTF-8',
+            body: '{}',
           },
-          // @ts-expect-error: node-fetch types don't seem to like FormData
-          body,
-        })
+        },
+        {
+          // Complex args are encoded as FormData. Validation should happen
+          // before decoding this intentionally empty payload.
+          name: 'form-data/multipart',
+          request: {
+            body: new FormData(),
+          },
+        },
+      ])(
+        'should reject a server action request to a nonexistent page: $name',
+        async ({ request: { contentType, body } }) => {
+          const res = await next.fetch('/non-existent-route', {
+            method: 'POST',
+            headers: {
+              'next-action': actionId,
+              ...(contentType ? { 'content-type': contentType } : undefined),
+            },
+            // @ts-expect-error: node-fetch types don't seem to like FormData
+            body,
+          })
 
-        expect(res.status).toBe(404)
+          expect(res.status).toBe(404)
 
-        const cliOutput = getLogs()
-        expect(cliOutput).not.toContain('TypeError')
-        expect(cliOutput).not.toContain(
-          'Missing `origin` header from a forwarded Server Actions request'
-        )
-        expect(cliOutput).toInclude(outdent`
-          Failed to find Server Action "123". This request might be from an older or newer deployment.
-          Read more: https://nextjs.org/docs/messages/failed-to-find-server-action
-        `)
-      }
-    )
+          const cliOutput = getLogs()
+          expect(cliOutput).not.toContain('TypeError')
+          if (expectedClassification === 'invalid') {
+            expect(cliOutput).toMatch(/server reference id/i)
+            expect(cliOutput).toMatch(/invalid|malformed|format/i)
+          } else {
+            expect(cliOutput).toMatch(/server action/i)
+            expect(cliOutput).toMatch(/not found|missing|failed to find/i)
+            expect(cliOutput).not.toMatch(
+              /server reference id.{0,100}(invalid|malformed|format)/i
+            )
+          }
+        }
+      )
+    })
   }
 
   it('should error when POSTing a urlencoded action to a nonexistent page', async () => {
@@ -144,12 +167,14 @@ describe('unrecognized server actions', () => {
           )
 
           if (!isNextDeploy) {
-            await retry(async () =>
-              expect(getLogs()).toInclude(outdent`
-              Failed to find Server Action "decafc0ffeebad01". This request might be from an older or newer deployment.
-              Read more: https://nextjs.org/docs/messages/failed-to-find-server-action
-            `)
-            )
+            await retry(async () => {
+              const output = getLogs()
+              expect(output).toMatch(/server action/i)
+              expect(output).toMatch(/not found|missing|failed to find/i)
+              expect(output).not.toMatch(
+                /server reference id.{0,100}(invalid|malformed|format)/i
+              )
+            })
           }
         } else {
           // An MPA action, sent without JS.
@@ -180,11 +205,14 @@ describe('unrecognized server actions', () => {
             }
 
             if (!isNextDeploy) {
-              await retry(async () =>
-                expect(getLogs()).toInclude(
-                  `Error: Failed to find Server Action. This request might be from an older or newer deployment`
+              await retry(async () => {
+                const output = getLogs()
+                expect(output).toMatch(/server action/i)
+                expect(output).toMatch(/not found|missing|failed to find/i)
+                expect(output).not.toMatch(
+                  /server reference id.{0,100}(invalid|malformed|format)/i
                 )
-              )
+              })
             }
           }
         }
diff --git a/test/e2e/app-dir/actions-unrecognized/app/nodejs/unrecognized-action/page.tsx b/test/e2e/app-dir/actions-unrecognized/app/nodejs/unrecognized-action/page.tsx
index 5924ba4d09..bb0ed25389 100644
--- a/test/e2e/app-dir/actions-unrecognized/app/nodejs/unrecognized-action/page.tsx
+++ b/test/e2e/app-dir/actions-unrecognized/app/nodejs/unrecognized-action/page.tsx
@@ -8,7 +8,7 @@ const action = async (...args: any[]) => {
 }
 
 // simulate client-side version skew by changing the action ID to something the server won't recognize
-setServerActionId(action, 'decafc0ffeebad01')
+setServerActionId(action, '0'.repeat(42))
 
 export default function Page() {
   return (
diff --git a/test/e2e/app-dir/no-server-actions/no-server-actions.test.ts b/test/e2e/app-dir/no-server-actions/no-server-actions.test.ts
index f384c9dc5c..e7e4285eaf 100644
--- a/test/e2e/app-dir/no-server-actions/no-server-actions.test.ts
+++ b/test/e2e/app-dir/no-server-actions/no-server-actions.test.ts
@@ -1,28 +1,53 @@
 import { nextTestSetup } from 'e2e-utils'
 
 describe('app-dir - no server actions', () => {
+  const missingActionId = '0'.repeat(42)
+
   const { next, isNextDeploy } = nextTestSetup({
     files: __dirname,
   })
 
-  it('should error when triggering a fetch action on an app with no server actions', async () => {
-    const res = await next.fetch('/', {
-      method: 'POST',
-      headers: {
-        'Next-Action': 'abc123',
-      },
-    })
+  it.each([
+    {
+      description: 'a malformed id',
+      actionId: 'abc123',
+      expectedClassification: 'invalid',
+    },
+    {
+      description: 'a plausible but missing id',
+      actionId: missingActionId,
+      expectedClassification: 'missing',
+    },
+  ])(
+    'should reject a fetch action with $description on an app with no server actions',
+    async ({ actionId, expectedClassification }) => {
+      const outputPosition = next.cliOutput.length
+      const res = await next.fetch('/', {
+        method: 'POST',
+        headers: {
+          'Next-Action': actionId,
+        },
+      })
 
-    expect(res.status).toBe(404)
-    expect(res.headers.get('x-nextjs-action-not-found')).toBe('1')
+      expect(res.status).toBe(404)
+      expect(res.headers.get('x-nextjs-action-not-found')).toBe('1')
 
-    // Runtime logs and custom headers are not forwarded to the client when deployed.
-    if (!isNextDeploy) {
-      expect(next.cliOutput).toContain(
-        'Failed to find Server Action "abc123". This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action'
-      )
+      // Runtime logs are not available when deployed.
+      if (!isNextDeploy) {
+        const output = next.cliOutput.slice(outputPosition)
+        if (expectedClassification === 'invalid') {
+          expect(output).toMatch(/server reference id/i)
+          expect(output).toMatch(/invalid|malformed|format/i)
+        } else {
+          expect(output).toMatch(/server action/i)
+          expect(output).toMatch(/not found|missing|failed to find/i)
+          expect(output).not.toMatch(
+            /server reference id.{0,100}(invalid|malformed|format)/i
+          )
+        }
+      }
     }
-  })
+  )
 
   it('should error when triggering an MPA action on an app with no server actions', async () => {
     const formData = new FormData()