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.

#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.