loginForTest with two apps

api

#1

There is this awesome function loginForTest in the Node API. I’ve used it for writing some small tests, like the examples from the API.

I’m wondering whether it’s possible to use it to login twice as the same user. That way it’s possible to test inter-app communication situations.

The following example is something I’d like to do:

// First app creates its app container
{
    const info = { id: 'primary', name: 'Primary App', vendor: '1' };

    const app = await safeApp.initializeApp(info);
    await app.auth.loginForTest({}, { own_container: true });
}

// Second app should access it
{
    const info = { id: 'secondary', name: 'Secondary App', vendor: '2' };
    const permissions = {
        'apps/primary': ['Read'], // Permission to read primary app container
    };

    const app2 = await safeApp.initializeApp(info);

    await app2.auth.loginForTest(permissions, {});

    // Access primary app container (app.auth.getContainer)
}

I’ve tried, but I get the following:

thread '<unnamed>' panicked at '

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!   unwrap! called on Result::Err                                              !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
src\test_utils.rs:89,23 in safe_app::test_utils

Err(
    Unexpected(
        "\'apps/primary\' not found in the access container"
    )
)

', C:\Users\viv\.cargo\registry\src\github.com-1ecc6299db9ec823\unwrap-1.1.0\src\lib.rs:67:24
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Hard coded URI to test app container
#2

Hi @bzee - interesting question. There might not be anything stopping it in the back-end but I’m not 100% sure. Give me a little time and I’ll ask around and see if there’s any ideas.
David.


#3

Hi @bzee! Sorry for replying late - so answering your question,

On the SAFE Client Libs level, I see no single reason for this not to work.

Actually, I’ve tried to reproduce your test case in Rust and it works for me – so I think this error you’re seeing has more to do with the specifics of loginForTest or the JavaScript API rather than the availability of such an option.

So probably @bochaco or @hunterlester can chime in and provide a more concrete answer about it.


#4

Hey @nbaksalyar, your test doesn’t seem to map what @bzee is trying to do, he is creating two apps with test_create_app_with_access, I can see you are using register_app instead. I’m able to reproduce the same issue with the following test in safe_app_nodejs.

Our loginForTest simply calls test_create_app_with_access if permissions are requested, or test_create_app if not.

Nikita, do you have an analogous test which does this but with test_create_app_with_access instead?


#5

This topic was automatically closed after 60 days. New replies are no longer allowed.