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

issue #4494 Allow endpoint handlers configurations from inside a test #4952

Closed

Conversation

rrrooommmaaa
Copy link
Contributor

This PR allows to configure handlers from inside a test
(also sets up one test in this way as a demo -- user3@standardsubdomainfes.localhost:8001 - PWD encrypted message with FES web portal - pubkey recipient in bcc

TODO: clear handlers after test finishes (if MockApi is reused)?
issue #4494


Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@rrrooommmaaa
Copy link
Contributor Author

As I understand, we want something like this, @tomholub @sosnovsky ?

Comment on lines +2551 to +2560
t.mockApi?.setHandlers({
...mockGoogleEndpoints,
// ...mockBackendEndpoints,
...mockAttesterEndpoints,
...mockKeyManagerEndpoints,
// ...mockWkdEndpoints,
// ...mockSksEndpoints,
...mockCustomerUrlFesEndpoints,
// ...mockSharedTenantFesEndpoints,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean this way, setting handlers.

I meant we would be setting configuration. Since now we have one MockApi per per test, we have an opportunity to configure mock api with different data (or expectations).

Like this:

    mockApi.fesConfig = { ... }; // particular client configuration for this test
    mockApi.ekmConfig = { returnKeys: [ekmKeySamples.e2eValidKey.prv] } // same
    mockApi.attesterConfig = { ... }; // configure Attester with particular public keys for this test 
    mockApi.googleConfig = {
      accounts: {
        'e2e.enterprise.test@flowcrypt.com': { // which account is allowed for Gmail login in this test
          messages: ['CC and BCC test'], // exported messages pre-loaded for this test, by subject
        }
      }
    }

notice it's receiving information on what to return (per service), not receiving the endpoints directly as done in the PR.

Have a look at any iOS mock tests, like these:
https://github.com/FlowCrypt/flowcrypt-ios/blob/master/appium/tests/specs/mock/composeEmail/CheckInvalidEmailRecipient.spec.ts
https://github.com/FlowCrypt/flowcrypt-ios/blob/master/appium/tests/specs/mock/composeEmail/CheckSendAsAlias.spec.ts

Notice how each test has some unique mock api configuration to work with, so it's clear which data the test needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean this way, setting handlers.

I meant we would be setting configuration. Since now we have one MockApi per per test, we have an opportunity to configure mock api with different data (or expectations).

My suggestion doesn't rule out a configuration structure. It's just more straightforward to define endpoints in this way, for example:

const gmailData = GoogleData.withInitializedData(...).filter(...); // leave only a subset
t.mockApi?.setHandlers([
gmailGetMessage(gmailData), 
gmailSendMessage(gmailData)
]);
// do some tests
...
// read messages in gmailData

Thus we see what endpoints are expected to be used in this test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for me, it'll just make tests setup more complicated if we'll need to set handlers separately for each test, while it won't give us any advantages in tests configuration.

While setting custom fesConfig, ekmConfig etc will allow us to have fully independent tests with different configs. They also can be updated during the test like this:

// test setup
mockApi.ekmConfig = { .. };
...
// some test code
...
mockApi.ekmConfig = { ... }; // updated config
// another test code
...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @sosnovsky in that @rrrooommmaaa 's approach seems more complex to set up for each test, without clear advantage compared to what was in the issue. Yes, it would allow to fine-tune which exact endpoints are allowed for the test, which would be more precise. But I don't think we need to go that far, and for tests that truly intend to test that, using @sosnovsky 's approach also doesn't mean we can't have a configuration to disallow certain exact endpoints for that test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you to decide.
However, as of PR #4928, mockApi isn't exposed to the test definition, or am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently it's not exposed, I was planning to add it to AvaContext:

t.mockApi = await startMockApiAndCopyBuild(t);

(here - https://github.com/FlowCrypt/flowcrypt-browser/blob/master/test/source/test.ts#L68)

And then use it in tests like this:

t.mockApi.fesConfig = { ... };
t.mockApi.ekmConfig = { ... };

@tomholub
Copy link
Collaborator

I'll close this attempt - as it's quite different from the intended appraoch

@tomholub tomholub closed this Mar 16, 2023
@rrrooommmaaa
Copy link
Contributor Author

I'll close this attempt - as it's quite different from the intended appraoch

I'm afraid we'll have to wait for half a year for the intended approach to be implemented -- and the tests behave very unstable right now

@tomholub
Copy link
Collaborator

Understood, that indeed sucks - I'll prioritize this for next month for @ioanmo226 to get started on.

@ioanmo226
Copy link
Collaborator

Okay

@tomholub
Copy link
Collaborator

#5021

@sosnovsky sosnovsky deleted the issue-4494-allow-endpoint-configuration-from-test branch August 7, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants