ts-odd
ts-odd copied to clipboard
How to mock `permissions`?
Summary
How do I set permissions/authenticate in a test context?
This is the repo I am working with: wn-blob . The example uses demo permissions, but returns an 'not authorized' response
{
scenario: 'NOT_AUTHORISED',
permissions: {
app: { name: 'test', creator: 'nichoth' },
fs: { public: [Array] }
},
authenticated: false
const PERMISSIONS = {
app: {
name: "test",
creator: "nichoth",
},
fs: {
public: [ webnative.path.directory('test') ],
}
};
Problem
Should be able to use webnative
as a dependency in other repos.
Impact
Can't run tests that use webnative
Solution
Document how to mock permissions
Sorry for not getting back to this earlier. If this is too late for you, I hope it's at least helpful to others coming across this.
The short answer is: We don't support this yet.
Long answer:
From reading this:
Impact
Can't run tests that use webnative
This looks somewhat like an X/Y problem: You want to run tests with webnative, not necessarily mock permissions, right?
Well, we don't quite fully support running webnative in nodejs today. At some point we hacked together a way to run webnative in nodejs for our own purposes, but it's not something we mean to support officially at the moment.
That said, you can take a look at the setup/node.ts
file which sets up a mocked keystore-idb and mocks the indexeddb stuff, so we can run webnative tests in the browser.
We have to avoid calling the webnative.initialise
function though. Instead, we construct file systems directly:
https://github.com/fission-suite/webnative/blob/4cf1af3de784a9cba220e051661d7a3264dc04be/tests/helpers/filesystem.ts#L10-L20
It's technically also possible to more advanced things in nodejs, for example run data root updates or fetch the file system from an existing account. You can see more of that in the implementation of wnfs-migration.
Hope this helps.
Thanks for the reply. I had forgotten that I was doing this; so I'm getting re-acquainted with this also, and I don't remember all the context for this issue.
To clarify one thing — this is actually running in a browser environment (electron). The test are using a utility called tape-run
that does this — https://github.com/nichoth/wn-blob/blob/main/package.json#L17
this is actually running in a browser environment
Ah interesting, that clarifies some things.
Then you may be interested in the app-owned-login stuff that @bgins is working on right now. That should make it easier to initialise webnative in a way that doesn't run a redirect to https://auth.fission.codes, and instead makes it run independently, similar to what the auth lobby itself is doing.
Hey @nichoth 👋
We have app-owned account registration (https://github.com/fission-suite/webnative/pull/330) and account linking (https://github.com/fission-suite/webnative/pull/335) available in the latest release of webnative (released today!). One thing that is missing that you may need is WNFS. Keep an eye on issue https://github.com/fission-suite/webnative/issues/368 where I'm currently working on that.
With all those pieces, apps should be able to make an account, link devices, and have their own WNFS without using the auth lobby to set things up.
Yes, and specifically I think nichoth would need WNFS support, but no account registration nor account linking, only WNFS (if that's possible?), because it's just for tests.
It's much easier to run tests in NodeJS now, see webnative's tests.
You don't necessarily need to run webnative.program
to prepare for tests.