Skip to content

Commit

Permalink
fix: add auth status inactive category handling to GA in userDeletion…
Browse files Browse the repository at this point in the history
… flow (#2669)
  • Loading branch information
sanpj2292 authored Sep 29, 2023
1 parent 4d6c4b8 commit b784800
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
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];

0 comments on commit b784800

Please sign in to comment.