-
Notifications
You must be signed in to change notification settings - Fork 113
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
feat: update proxy tests for cm360 #3039
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9dd8625
feat: update proxy tests for cm360
utsabc 650911e
fix: typo
utsabc 84b6a5d
Update test/integrations/destinations/campaign_manager/dataDelivery/b…
utsabc 686f524
Update test/integrations/destinations/campaign_manager/dataDelivery/b…
utsabc 76e0284
fix: api contract for v1 proxy
utsabc 93947db
fix: api contract for v1 proxy (#3049)
utsabc d2e65f4
chore: clean up zod type
7ce0a66
chore: update testutils
99f5cb2
chore: update V0 proxy request type and zod schema
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,139 @@ | ||
import { z } from 'zod'; | ||
import { isDefinedAndNotNullAndNotEmpty } from '@rudderstack/integrations-lib'; | ||
import { isHttpStatusSuccess } from '../v0/util'; | ||
|
||
export const ProxyMetadataSchema = z.object({ | ||
jobId: z.number(), | ||
attemptNum: z.number(), | ||
userId: z.string(), | ||
sourceId: z.string(), | ||
destinationId: z.string(), | ||
workspaceId: z.string(), | ||
secret: z.record(z.unknown()), | ||
destInfo: z.object({}).optional(), | ||
omitempty: z.record(z.unknown()).optional(), | ||
dontBatch: z.boolean(), | ||
koladilip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
export const ProxyV0RequestSchema = z.object({ | ||
version: z.string(), | ||
type: z.string(), | ||
method: z.string(), | ||
endpoint: z.string(), | ||
userId: z.string(), | ||
headers: z.record(z.unknown()).optional(), | ||
params: z.record(z.unknown()).optional(), | ||
body: z | ||
.object({ | ||
JSON: z.record(z.unknown()).optional(), | ||
JSON_ARRAY: z.record(z.unknown()).optional(), | ||
XML: z.record(z.unknown()).optional(), | ||
FORM: z.record(z.unknown()).optional(), | ||
}) | ||
.optional(), | ||
files: z.record(z.unknown()).optional(), | ||
metadata: ProxyMetadataSchema, | ||
chandumlg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
destinationConfig: z.record(z.unknown()), | ||
}); | ||
|
||
export const ProxyV1RequestSchema = z.object({ | ||
version: z.string(), | ||
type: z.string(), | ||
method: z.string(), | ||
endpoint: z.string(), | ||
userId: z.string(), | ||
headers: z.record(z.unknown()).optional(), | ||
params: z.record(z.unknown()).optional(), | ||
body: z | ||
.object({ | ||
JSON: z.record(z.unknown()).optional(), | ||
JSON_ARRAY: z.record(z.unknown()).optional(), | ||
XML: z.record(z.unknown()).optional(), | ||
FORM: z.record(z.unknown()).optional(), | ||
}) | ||
.optional(), | ||
files: z.record(z.unknown()).optional(), | ||
metadata: z.array(ProxyMetadataSchema), | ||
destinationConfig: z.record(z.unknown()), | ||
}); | ||
|
||
const validateStatTags = (data: any) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}; | ||
|
||
const validateAuthErrorCategory = (data: any) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.authErrorCategory); | ||
} | ||
return true; | ||
}; | ||
|
||
export const DeliveryV0ResponseSchema = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
destinationResponse: z.unknown(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
}) | ||
.refine(validateStatTags, { | ||
// eslint-disable-next-line sonarjs/no-duplicate-string | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}); | ||
|
||
export const DeliveryV0ResponseSchemaForOauth = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
destinationResponse: z.unknown(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}) | ||
.refine(validateAuthErrorCategory, { | ||
message: "authErrorCategory can't be empty when status is not a 2XX", | ||
path: ['authErrorCategory'], // Pointing out which field is invalid | ||
}); | ||
|
||
const DeliveryJobStateSchema = z.object({ | ||
error: z.string(), | ||
statusCode: z.number(), | ||
metadata: ProxyMetadataSchema, | ||
}); | ||
|
||
export const DeliveryV1ResponseSchema = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
response: z.array(DeliveryJobStateSchema), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}); | ||
|
||
export const DeliveryV1ResponseSchemaForOauth = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
response: z.array(DeliveryJobStateSchema), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}) | ||
.refine(validateAuthErrorCategory, { | ||
message: "authErrorCategory can't be empty when status is not a 2XX", | ||
path: ['authErrorCategory'], // Pointing out which field is invalid | ||
}); |
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,109 @@ | ||
// Ads API | ||
// Ref: https://developers.google.com/google-ads/api/docs/get-started/common-errors | ||
|
||
export const networkCallsData = [ | ||
{ | ||
description: 'Mock response depicting CREDENTIALS_MISSING error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_credentials_missing', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 401, | ||
message: | ||
'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.', | ||
errors: [ | ||
{ | ||
message: 'Login Required.', | ||
domain: 'global', | ||
reason: 'required', | ||
location: 'Authorization', | ||
locationType: 'header', | ||
}, | ||
], | ||
status: 'UNAUTHENTICATED', | ||
details: [ | ||
{ | ||
'@type': 'type.googleapis.com/google.rpc.ErrorInfo', | ||
reason: 'CREDENTIALS_MISSING', | ||
domain: 'googleapis.com', | ||
metadata: { | ||
method: 'google.ads.xfa.op.v4.DfareportingConversions.Batchinsert', | ||
service: 'googleapis.com', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
status: 401, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting ACCESS_TOKEN_SCOPE_INSUFFICIENT error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_access_token_scope_insufficient', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 403, | ||
message: 'Request had insufficient authentication scopes.', | ||
errors: [ | ||
{ | ||
message: 'Insufficient Permission', | ||
domain: 'global', | ||
reason: 'insufficientPermissions', | ||
}, | ||
], | ||
status: 'PERMISSION_DENIED', | ||
details: [ | ||
{ | ||
'@type': 'type.googleapis.com/google.rpc.ErrorInfo', | ||
reason: 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', | ||
domain: 'googleapis.com', | ||
metadata: { | ||
service: 'gmail.googleapis.com', | ||
method: 'caribou.api.proto.MailboxService.GetProfile', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
status: 403, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response for google.auth.exceptions.RefreshError invalid_grant error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_invalid_grant', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 403, | ||
message: 'invalid_grant', | ||
error_description: 'Bad accesss', | ||
}, | ||
}, | ||
status: 403, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response for google.auth.exceptions.RefreshError refresh_token error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_refresh_error', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: 'unauthorized', | ||
error_description: 'Access token expired: 2020-10-20T12:00:00.000Z', | ||
}, | ||
status: 401, | ||
}, | ||
}, | ||
]; |
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,62 @@ | ||
export const networkCallsData = [ | ||
{ | ||
description: 'Mock response depicting SERVICE NOT AVAILABLE error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_service_not_available', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
message: 'Service Unavailable', | ||
description: | ||
'The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later.', | ||
}, | ||
}, | ||
status: 503, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting INTERNAL SERVER ERROR error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_internal_server_error', | ||
}, | ||
httpRes: { | ||
data: 'Internal Server Error', | ||
status: 500, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting GATEWAY TIME OUT error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_gateway_time_out', | ||
}, | ||
httpRes: { | ||
data: 'Gateway Timeout', | ||
status: 504, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting null response', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_null_response', | ||
}, | ||
httpRes: { | ||
data: null, | ||
status: 500, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting null and no status', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_null_and_no_status', | ||
}, | ||
httpRes: { | ||
data: null, | ||
}, | ||
}, | ||
]; |
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.
is this mandatory?
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.
https://github.com/rudderlabs/rudder-server/blob/master/router/transformer/transformer_proxy_adapter.go#L26
https://github.com/rudderlabs/rudder-server/blob/master/router/transformer/transformer.go#L67
From server it will be sent. Possible it could be empty
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.
can we make it optional