Skip to content
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

fix: add auth status inactive category handling to GA in userDeletion flow #2669

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/v0/destinations/ga/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { REFRESH_TOKEN } = require('../../../adapters/networkhandler/authConstants');
const {
REFRESH_TOKEN,
AUTH_STATUS_INACTIVE,
} = require('../../../adapters/networkhandler/authConstants');
const {
processAxiosResponse,
getDynamicErrorType,
Expand Down Expand Up @@ -29,6 +32,18 @@ const gaResponseHandler = (gaResponse) => {
if (isInvalidCredsError || response?.error?.status === 'UNAUTHENTICATED') {
throw new InvalidAuthTokenError('invalid credentials', 500, response, REFRESH_TOKEN);
}
const isInvalidGrantError =
response?.error.code === 403 &&
response.error?.errors?.some((errObj) => errObj.reason === 'insufficientPermissions');
if (isInvalidGrantError) {
throw new InvalidAuthTokenError(
response?.error?.message || 'insufficent permissions',
400,
response,
AUTH_STATUS_INACTIVE,
);
}

throw new NetworkError(
`Error occurred while completing deletion request: ${response.error?.message}`,
status,
Expand Down
42 changes: 42 additions & 0 deletions test/integrations/destinations/ga/deleteUsers/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AUTH_STATUS_INACTIVE } from '../../../../../src/adapters/networkhandler/authConstants';

export const data = [
{
name: 'ga',
Expand Down Expand Up @@ -136,4 +138,44 @@ export const data = [
},
},
},
{
name: 'ga',
description: 'Test 3',
feature: 'userDeletion',
module: 'destination',
version: 'v0',
input: {
request: {
headers: {
'x-rudder-dest-info': '{"secret": { "access_token": "no_permissions_token" }}',
},
body: [
{
destType: 'GA',
userAttributes: [
{
userId: 'test_user_20',
},
],
config: {
trackingID: 'UA-123456789-7',
useNativeSDK: false,
},
},
],
},
},
output: {
response: {
status: 400,
body: [
{
statusCode: 400,
authErrorCategory: AUTH_STATUS_INACTIVE,
error: 'User does not have sufficient permissions',
},
],
},
},
},
];
34 changes: 34 additions & 0 deletions test/integrations/destinations/ga/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,39 @@ const deleteNwData = [
statusText: 'OK',
},
},
{
httpReq: {
method: 'post',
url: 'https://www.googleapis.com/analytics/v3/userDeletion/userDeletionRequests:upsert',
data: {
kind: 'analytics#userDeletionRequest',
id: {
type: 'USER_ID',
userId: 'test_user_20',
},
webPropertyId: 'UA-123456789-7',
},
headers: {
Authorization: 'Bearer no_permissions_token',
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
httpRes: {
data: {
error: {
errors: [
{
reason: 'insufficientPermissions',
},
],
code: 403,
message: 'User does not have sufficient permissions',
},
},
status: 200,
statusText: 'OK',
},
},
];
export const networkCallsData = [...deleteNwData];
Loading