-
Notifications
You must be signed in to change notification settings - Fork 4
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
CLI and Client & Agent Service test splitting #311
Conversation
I've encountered a problem with the identities CLI - as far as I can see there isn't a command to add a node or identity to the gestalt graph, or any other command that would do this as a side-effect. Since the node/identity needs to be added to the graph before we can allow/disallow permissions (and probably other operations too), I can't see a way for these commands to work from a CLI perspective? These tests were previously setting the nodes/identities manually (e.g. |
Related to my previous comment - there also aren't CLI commands for the identities token manipulation grpc handlers (i.e. |
I believe that you can definitely authenticate via the CLI. But it involves using the browser. @joshuakarp had previously mocked the TestProvider/browser call so that it was fully automated in the tests. All other identities related functionality would require mocking and enhancing the flexibility of the TestProvider. Right now I'm not sure if the TestProvider is applied on the global shared agent. This was something we had discussed but didn't get around to. In which case I suggest you focus on the other test areas to first split. We can then circle back to the TestProvider problem and mock it's behaviour. And yes there should probably be more identities CLI calls, we hadn't fully reviewed the workflow here yet. |
ae2e5fd
to
2921efe
Compare
Just a note about the final describe block that exists for bin tests that use the global agent. Make sure to name the describe like this:
Replace the |
Decided to move onto the GRPC tests since there are a lot of things blocking the CLI tests (need to look into mocking the identities manager + gestalt graph and/or adding more CLI calls to fill gaps), however there are errors in
Not sure what change between when the file was created 9 days ago and now has caused this issue. |
The tests that have been split up so far and that are passing are:
I've also done |
All uses of the global shared agent is serialised with mutual exclusion. So any test with side-effects just needs to reverse those side-effects at the end. As long as the ability to reverse is available, then testing should be possible. |
The keys CLI tests have all been split into their own files. I was having issues with keys reset where the agent was needing to be stopped and restarted after calling |
@emmacasolin when you get to the TestProvider mocking stage. Consider that there are 3 ways of doing mocking.
We have used all 3 mocking patterns in other test areas. Consult with @tegefaulkes to get an idea of how to do it. I reckon we would need to mock the |
Btw if you find places where side effects can't be reversed (and no, not with a clear method), those places should add the opposite method to keep their APIs symmetric. However I know that say Sigchain may not be capable of doing this. At least not for a single claim. But then a general reset of the sigchain can be exposed to the client service that allows complete wipe. |
When this is ready, feel free to merge back into |
To resolve this. Go to Replace test expectations using Import the symbol |
Why do we need to restart the agent when calling keys reset? It should work without doing this. If it requires a restart, that would be a bug. |
In that case I'll play around with it and see what's going on. It could just be an issue with timing, not sure. |
The error that's occurring on commands that follow |
Ah yes so basically when this happens the new node ID should be used by the client GRPCClient. Or if this is between agent to agent, then the new TLSConfig must be set for the Forward and Reverse proxies. This was something we had to a while ago for agent to agent networking and we provisioned for this instance. Look at the handler for key reset and the associated KeyManager method, see how it's supposed to rencrypt all the keys and reset the TLSConfig. The whole process is meant to be a graceful swap. |
The problem with |
During my meeting today with @tegefaulkes, we decided that the simplest way to "mock" the Test Provider usage was to just register it during the setup of the global agent in |
Yea I think that's a good idea. But the question is how to do it, whether by module mocking or class method mocking? Do we use the jest.mock or jest.spyOn? |
I'm thinking that injecting status like this isn't the best idea and instead composition should be used. But I need to think how to propagate changes of keypair changes to all the places that need to be updated when the keypair changes. |
Just simply calling the const pkAgent = await PolykeyAgent.createPolykeyAgent({
password: globalAgentPassword,
nodePath: globalAgentDir,
keysConfig: {
rootKeyPairBits: 1024
},
seedNodes: {}, // explicitly no seed nodes on startup
logger,
});
pkAgent.identitiesManager.registerProvider(new TestProvider()); This has already been added to |
But the global shared agent doesn't give you access to the PK agent.
On 30 December 2021 7:35:21 pm AEDT, emmacasolin ***@***.***> wrote:
> Yea I think that's a good idea. But the question is how to do it, whether by module mocking or class method mocking? Do we use the jest.mock or jest.spyOn?
Just simply calling the `registerProvider()` function as usual:
```ts
const pkAgent = await PolykeyAgent.createPolykeyAgent({
password: globalAgentPassword,
nodePath: globalAgentDir,
keysConfig: {
rootKeyPairBits: 1024
},
seedNodes: {}, // explicitly no seed nodes on startup
logger,
});
pkAgent.identitiesManager.registerProvider(new TestProvider());
```
This has already been added to `tests/utils.ts` (lines 112-121) and the `authenticate` test is passing with this method of doing it. We're actually registering the test provider so no mocking is needed.
--
Reply to this email directly or view it on GitHub:
#311 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
We don't need to access it - the registration is being done inside the |
Yep I forgot it was changed over to like that. So that should be sufficient, you can proceed with that solution. |
I've implemented the observer pattern to enable places that need to be updated when the keypair is changed to do so automatically. The relevant tests are passing, but the naming I've used isn't great so I want to fix that at some point. At the moment only |
7c686b1
to
87f2b93
Compare
87f2b93
to
8c25f3f
Compare
8c25f3f
to
4fa172d
Compare
The remaining instances of
While all of these warnings are for the same error, there are other occurances of the same warning where the host takes the correct value of |
4fa172d
to
e261da0
Compare
I've checked the final The final nodes related issues above will be addressed in #326. |
Description
This PR will split our CLI and GRPC API tests into individual files for each command/handler, as well as refactor the tests to improve performance and coverage.
Issues Fixed
tests/
#306KeyManager
#312Tasks
tests/bin
,tests/client
, andtests/agent
:identitiesTokenGet
/identitiesTokenPut
/identitiesTokenDelete
)tests/bin/agent/status.test.ts
where appropriatepkExec
,pkStdio
,pkSpawn
,pkExpect
utilitybeforeEach
andafterEach
WARN
is the default whereverLogLevel
is usedGRPCClientClient.test.ts
andGRPCClientAgent.test.ts
clearXXX()
with destroy methods in testspolykeyStartupTimeout
withdefaultTimeout
tests/
#306EventBus
into PK to be used for asynchronously emitting root keypair changesTests that need splitting:
tests/bin
(these should be fully simulated wherever possible using the global agent, then own agent using global keypair, then own agent fully created from scratch)agent
identities
notifications
keys
nodes
- ETA [Thur 13/1]tests/client
(these can be mocked as much as possible and usually don't need a whole agent) - ETA [Wed 12/1]tests/agent
(these should be fully simulated wherever possible) - ETA [Mon 17/1]########################################################################
Tests that cannot yet be addressed:
Commands that may be removed
tests/bin/agent/restart
tests/client/service/agentRestart
Commands that will be implemented/fixed in #266
tests/bin/secrets
tests/bin/vaults
tests/client/service
tests/agent/service
Tests that are yet to be written in #326
Other unimplemented commands
tests/agent/service/nodesClaimsGet
Final checklist