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

Manual test re-auth failing to fetch #52281

Closed
wants to merge 7 commits into from
Closed
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: 17 additions & 0 deletions src/libs/Authentication.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import CONFIG from '@src/CONFIG';

Check failure on line 1 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `import·Onyx·from·'react-native-onyx';⏎`

Check failure on line 1 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `import·Onyx·from·'react-native-onyx';⏎`
import CONST from '@src/CONST';
import type Response from '@src/types/onyx/Response';
import * as Delegate from './actions/Delegate';
import updateSessionAuthTokens from './actions/Session/updateSessionAuthTokens';
import redirectToSignIn from './actions/SignInRedirect';
import HttpsError from './Errors/HttpsError';
import * as ErrorUtils from './ErrorUtils';
import Log from './Log';
import * as Network from './Network';
import * as NetworkStore from './Network/NetworkStore';
import requireParameters from './requireParameters';

Check failure on line 12 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Delete `';⏎import·Onyx·from·'react-native-onyx`

Check failure on line 12 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Delete `';⏎import·Onyx·from·'react-native-onyx`
import Onyx from 'react-native-onyx';

Check failure on line 13 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

`react-native-onyx` import should occur before import of `./actions/Delegate`

Check failure on line 13 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`react-native-onyx` import should occur before import of `./actions/Delegate`

let authenticateCalls = 0;
const CALLS_TO_FAIL = 10;

type Parameters = {
useExpensifyLogin?: boolean;
Expand All @@ -26,6 +31,7 @@

requireParameters(['partnerName', 'partnerPassword', 'partnerUserID', 'partnerUserSecret'], parameters, commandName);

authenticateCalls++;
return Network.post(commandName, {
// When authenticating for the first time, we pass useExpensifyLogin as true so we check
// for credentials for the expensify partnerID to let users Authenticate with their expensify user
Expand All @@ -44,6 +50,17 @@

// Add email param so the first Authenticate request is logged on the server w/ this email
email: parameters.email,
}).then((response) => {
if (authenticateCalls > CALLS_TO_FAIL) {
console.log('Ndebug Authenticate success after failing calls: ', CALLS_TO_FAIL);

Check failure on line 55 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unexpected console statement

Check failure on line 55 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected console statement
Onyx.set('failedAuthenticate', false);

Check failure on line 56 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Only actions should directly set or modify Onyx data. Please move this logic into a suitable action

Check failure on line 56 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Only actions should directly set or modify Onyx data. Please move this logic into a suitable action

Check failure on line 56 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '"failedAuthenticate"' is not assignable to parameter of type 'OnyxKey'.
return response;
}
console.log('Ndebug failing to fetch in Authenticate. Call number: ', authenticateCalls);

Check failure on line 59 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unexpected console statement

Check failure on line 59 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected console statement
Onyx.set('failedAuthenticate', true);

Check failure on line 60 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Only actions should directly set or modify Onyx data. Please move this logic into a suitable action

Check failure on line 60 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Only actions should directly set or modify Onyx data. Please move this logic into a suitable action

Check failure on line 60 in src/libs/Authentication.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '"failedAuthenticate"' is not assignable to parameter of type 'OnyxKey'.
throw new HttpsError({
message: CONST.ERROR.FAILED_TO_FETCH,
});
});
}

Expand Down
28 changes: 27 additions & 1 deletion src/libs/Request.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import CONST from '@src/CONST';

Check failure on line 1 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `import·Onyx·from·'react-native-onyx';⏎`

Check failure on line 1 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `import·Onyx·from·'react-native-onyx';⏎`
import type Request from '@src/types/onyx/Request';
import type Response from '@src/types/onyx/Response';
import HttpUtils from './HttpUtils';
import type Middleware from './Middleware/types';
import enhanceParameters from './Network/enhanceParameters';
import * as NetworkStore from './Network/NetworkStore';

Check failure on line 7 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Delete `';⏎import·Onyx·from·'react-native-onyx`

Check failure on line 7 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Delete `';⏎import·Onyx·from·'react-native-onyx`
import Onyx from 'react-native-onyx';

Check failure on line 8 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / ESLint check

`react-native-onyx` import should occur before import of `./HttpUtils`

Check failure on line 8 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`react-native-onyx` import should occur before import of `./HttpUtils`

let middlewares: Middleware[] = [];

let addCommentRequestCount = 0;

let failedAuthenticate;

Check failure on line 14 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / typecheck

Variable 'failedAuthenticate' implicitly has type 'any' in some locations where its type cannot be determined.
Onyx.connect({
key: 'failedAuthenticate',

Check failure on line 16 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / typecheck

Type '"failedAuthenticate"' is not assignable to type 'OnyxKey'.
callback: (val) => (failedAuthenticate = val),
});

function makeXHR(request: Request): Promise<Response | void> {
const finalParameters = enhanceParameters(request.command, request?.data ?? {});
return NetworkStore.hasReadRequiredDataFromStorage().then((): Promise<Response | void> => {
Expand All @@ -18,7 +28,23 @@
});
}

return HttpUtils.xhr(request.command, finalParameters, request.type, request.shouldUseSecure);
if (request.command === 'AddComment') {
addCommentRequestCount++;
}

return HttpUtils.xhr(request.command, finalParameters, request.type, request.shouldUseSecure).then((response) => {
// Early return if we're not forcing a not authenticated response
// Force it in these scenarios:
// If it's not an Authenticate request itself. Making that fail is done separately
// Every other add comment request for easy testing
// If we have already failed to re-authenticate, keep failing for realism
if (request.command === 'Authenticate' || (addCommentRequestCount % 2 === 0 && !failedAuthenticate)) {

Check failure on line 41 in src/libs/Request.ts

View workflow job for this annotation

GitHub Actions / typecheck

Variable 'failedAuthenticate' implicitly has an 'any' type.
return response;
}
console.log('Ndebug forcing return not authenticated');
response.jsonCode = CONST.JSON_CODE.NOT_AUTHENTICATED;
return response;
});
});
}

Expand Down
Loading