-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom auth in failure function #28
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
484cefc
feat: add context.cancel
CahidArda 00288e2
feat: add lazy fetch and rm context.rawInitialPayload
CahidArda 9b94610
fix: context.cancel
CahidArda 0ef8478
feat: rename errors
CahidArda 30e5315
fix: add lazyFetch for initial payload and context.call
CahidArda 14dce13
fix: add lazyFetch for parallel
CahidArda 6db31ce
fix: docstings
CahidArda 2630533
Merge branch 'main' into DX-1279-context-cancel
CahidArda 87b6eb8
fix: tests
CahidArda 2857350
Merge branch 'main' into DX-1279-context-cancel
CahidArda d78b08c
feat: add initialBody flag and large-payload integration tests
CahidArda c9c344b
fix: tests
CahidArda 6a6c038
fix: increase test durations
CahidArda 65015c6
fix: track counter in steps
CahidArda 3e4bc70
ci: increase test durations
CahidArda b0197fb
fix: rename parsePayload as processRawSteps and change params
CahidArda ab7f459
ci: disable large-payload tests
CahidArda c91cf2b
Merge branch 'main' into DX-1279-context-cancel
CahidArda 3b7e1a2
feat: run auth in failureFunction
CahidArda 0955d53
fix: handle 0 retries and empty body in context.call
CahidArda 2e20d5a
fix: increase test timeouts
CahidArda 6875612
ci: add redis.fail and route for testing auth check in handleFailure
CahidArda ee69a65
Merge branch 'main' into DX-1393-auth-in-failure-function
CahidArda 2467f53
fix: review
CahidArda 16b47d3
ci: fix import
CahidArda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
this directory has three tests | ||
- success: checking auth correctly | ||
- fail: auth failing | ||
- custom: define an workflow endpoint secured with custom auth (instead of receiver) and try to call it as if failure callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { WorkflowContext } from "@upstash/workflow"; | ||
import { serve } from "@upstash/workflow/nextjs"; | ||
import { fail } from "app/ci/upstash/redis"; | ||
import { nanoid } from "app/ci/utils"; | ||
|
||
|
||
export const { POST } = serve(async (context) => { | ||
if (context.headers.get("authorization") !== nanoid()) { | ||
return; | ||
}; | ||
}, { | ||
receiver: undefined, | ||
async failureFunction({ context }) { | ||
await fail(context as WorkflowContext) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { serve } from "@upstash/workflow/nextjs"; | ||
import { BASE_URL, CI_RANDOM_ID_HEADER, CI_ROUTE_HEADER, TEST_ROUTE_PREFIX } from "app/ci/constants"; | ||
import { testServe, expect } from "app/ci/utils"; | ||
import { FailureFunctionPayload, WorkflowContext } from "@upstash/workflow"; | ||
import { saveResult } from "app/ci/upstash/redis"; | ||
|
||
const header = `test-header-foo` | ||
const headerValue = `header-bar` | ||
const authentication = `Bearer test-auth-super-secret` | ||
const payload = "my-payload" | ||
|
||
const thirdPartyEndpoint = `${TEST_ROUTE_PREFIX}/auth/custom/target` | ||
|
||
const makeCall = async ( | ||
context: WorkflowContext, | ||
stepName: string, | ||
method: "GET" | "POST", | ||
expectedStatus: number, | ||
expectedBody: unknown | ||
) => { | ||
const randomId = context.headers.get(CI_RANDOM_ID_HEADER) | ||
const route = context.headers.get(CI_ROUTE_HEADER) | ||
|
||
if (!randomId || !route) { | ||
throw new Error("randomId or route not found") | ||
} | ||
|
||
const { status, body } = await context.call<FailureFunctionPayload>(stepName, { | ||
url: thirdPartyEndpoint, | ||
body: | ||
{ | ||
status: 200, | ||
header: "", | ||
body: "", | ||
url: "", | ||
sourceHeader: { | ||
[CI_ROUTE_HEADER]: [route], | ||
[CI_RANDOM_ID_HEADER]: [randomId] | ||
}, | ||
sourceBody: "", | ||
workflowRunId: "", | ||
sourceMessageId: "", | ||
}, | ||
method, | ||
headers: { | ||
[ CI_RANDOM_ID_HEADER ]: randomId, | ||
[ CI_ROUTE_HEADER ]: route, | ||
"Upstash-Workflow-Is-Failure": "true" | ||
} | ||
}) | ||
|
||
expect(status, expectedStatus) | ||
|
||
expect(typeof body, typeof expectedBody) | ||
expect(JSON.stringify(body), JSON.stringify(expectedBody)) | ||
} | ||
|
||
export const { POST, GET } = testServe( | ||
serve<string>( | ||
async (context) => { | ||
|
||
expect(context.headers.get(header)!, headerValue) | ||
|
||
await makeCall( | ||
context, | ||
"regular call should fail", | ||
"POST", | ||
500, | ||
{ | ||
error: "WorkflowError", | ||
message: "Not authorized to run the failure function." | ||
} | ||
) | ||
|
||
const input = context.requestPayload; | ||
expect(input, payload); | ||
|
||
await saveResult( | ||
context, | ||
"not authorized for failure" | ||
) | ||
}, { | ||
baseUrl: BASE_URL, | ||
retries: 0, | ||
} | ||
), { | ||
expectedCallCount: 4, | ||
expectedResult: "not authorized for failure", | ||
payload, | ||
headers: { | ||
[ header ]: headerValue, | ||
"authentication": authentication | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we check this? We already know it'd work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a checkpoint to make sure that the state is set in redis, and only difference is the
failWithoutContext
method