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

How to mock permissions? #324

Closed
nichoth opened this issue Nov 6, 2021 · 6 comments
Closed

How to mock permissions? #324

nichoth opened this issue Nov 6, 2021 · 6 comments
Assignees

Comments

@nichoth
Copy link
Contributor

nichoth commented Nov 6, 2021

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

@matheus23
Copy link
Contributor

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.

@nichoth
Copy link
Contributor Author

nichoth commented May 2, 2022

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

@matheus23
Copy link
Contributor

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.

@bgins
Copy link
Member

bgins commented May 4, 2022

Hey @nichoth 👋

We have app-owned account registration (#330) and account linking (#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 #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.

@matheus23
Copy link
Contributor

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.

@icidasset
Copy link
Contributor

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.

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

No branches or pull requests

4 participants