-
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
Changes from 4 commits
9dd8625
650911e
84b6a5d
686f524
76e0284
93947db
d2e65f4
7ce0a66
99f5cb2
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
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
|
||
}); | ||
|
||
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()), | ||
}); | ||
|
||
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( | ||
(data) => { | ||
koladilip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}, | ||
{ | ||
// 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( | ||
(data) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}, | ||
{ | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}, | ||
) | ||
.refine( | ||
(data) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.authErrorCategory); | ||
} | ||
return true; | ||
}, | ||
{ | ||
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( | ||
(data) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}, | ||
{ | ||
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( | ||
(data) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}, | ||
{ | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}, | ||
) | ||
.refine( | ||
(data) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
koladilip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return isDefinedAndNotNullAndNotEmpty(data.authErrorCategory); | ||
} | ||
return true; | ||
}, | ||
{ | ||
message: "authErrorCategory can't be empty when status is not a 2XX", | ||
path: ['authErrorCategory'], // Pointing out which field is invalid | ||
}, | ||
); |
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, | ||
}, | ||
}, | ||
]; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename these files to mockNetwork.ts ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mockHandler identifies mock by file name |
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, | ||
}, | ||
}, | ||
]; |
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