"Cannot get base site config" error in Spartacus - spartacus-storefront

We are using Multi-Site setup in Spartacus. It works fine, however when user enters URL with incorrect baseSite, Spartacus shows a blank page and throws an error in JS console Error: Cannot get base site config! Current url (https://www.example.com/xyz/) doesn't match any of url patterns of any base sites. (xyz is the incorrect baseSite identifier in this example).
Is there a way to handle this error and redirect user e.g. to 404 not found page in this case?

You have to implement your own class based on SiteContextConfigInitializer and override the method resolveConfig. Then add it to providers in your module: { provide: SiteContextConfigInitializer, useClass: YourSiteContextConfigInitializer }. Unfortunatelly I guess you must add also own methods for isCurrentBaseSite and get currentUrl (just copy and rename) because they are private.

Related

The Cypress test does not open the Powerapps page

I'm trying to run simple cypress test and get error like this:
but if i change visit url to another - it opens normally:
I cant understand why this does this error come with this url:
"baseUrl":"https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a"
another visible error:
code:
describe("Create request", () => {
it("Should have a link that navigates to office365 login", () => {
cy.visit("/");
cy.get('div[class="loginNeededText_uf5ohz"]').contains('Sign in to start using Power Apps');
});
});
P.S. Also can't load https://apps.powerapps.com/ page. Error:
In general
With Cypress, you should not try to visit or interact with sites or servers you do not control. The main purpose of Cypress is testing, so when you try to do anything else with it, the task will become significantly more complicated (you can read more about it in the Cypress documentation).
If you really need information from a 3rd party site, it is recommended you do it through an API — mainly with the cy.request() method (e.g., Microsoft has quite an extensive documentation on how to work with the Office 365 Management API).
Your case
When you visit the apps.powerapps.com, you are being redirected to the Microsoft login page — it has a different domain name, which breaks a same-origin policy causing the cross-origin error in the Cypress console.
Seems that the page you specified in the baseUrl returns a 404 status code, along with some ugly CORS errors in the console, which suggest an issue with the app itself. After you solved those, you would most probably face the need of authentication anyway, and it is better to do it through an API.
When I use your base URL https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a I see only blank screen and 404 error in the console, I am not redirected to login.
Maybe your URL should be https://apps.powerapps.com and after you login you can navigate to "/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a".

How do I need to configure MongooseIM to allow registering new users? Getting error: Can't register user at node: not_allowed

I am currently trying to add chat functionality with MongooseIM to an app that already comes with users/accounts.
The idea was to add a mongooseIM chat server and register all existing (and future) users with their user ID in mongooseIM.
Setup
I am working with the mongooseIM docker container and have set up a docker compose that loads custom configuration.
In the custom configuration, I have added the admin REST API and can do requests like listing all registered users or the available commands.
Problem
Whenever a new user should be registered through the API, I get the response:
Can't register user at node: not_allowed and a 500 status code.
Trying to register a user through mongooseimctl returns Error: account_unprivileged.
What I tried
I think I have been reading through the documentation and google results for about 6 hours by now.
Testing with the standard docker container (and no extra configuration) works from the command line, but I failed testing the API because I do not know how to access the API then (or if it is enabled at all). Maybe someone has a hint on this for me?
One idea was that the action really is not allowed, but the /commands route of the admin interface contains the register_user action in the results, so I think its enabled/allowed:
%{
"action" => "create",
"category" => "users",
"desc" => "Register a user",
"name" => "register_user"
},
When using the default docker container and trying to register a user for a non-existent domain also results in "not_allowed", so this could be a configuration problem. I have a host name configured in my mongooseim.toml config file:
[general]
loglevel = "warning"
hosts = ["myhost"]
default_server_domain = "myhost"
language = "en"
I am quite positive I am missing some configuration/setup somewhere and would appreciate any hints/help.
Edit 1
I added dummy authorization (== no authorization) to the config file:
[auth]
methods = ["dummy"]
Now, I no longer get a "not_allowed" error.
Instead, the response always states the user already exists, while requesting the user list always returns an empty list.
I tried sending messages between made-up user jids, i get no errors, but also no messages are returned for any users.
"dummy" method is for testing only. It makes any user to exist (check ejabberd_auth_dummy.erl code, it is really just a dummy without any implementation).
You should use internal or rdbms auth_methods instead.
rdbms method would need an rdbms connection configured.
internal method is used to store users in Mnesia (but Mnesia backends are not recommended because RDBMS just works more reliably and efficiently).

Auth0 and angular2: how to set callbackURL and catch the token?

I am trying to implement passwordless authentication with Auth0 and angular2 (2.0.0-rc.6), using angular2-webpack-starter and auth0-lock-passwordless.
The form displays normally, and the authentication e-mail is sent using this code:
this.lock.magiclink({
callbackURL:"http://localhost:3000/#/sandbox"
});
The issues occur after I click the magic link in the e-mail:
Even though the redirect_uri of the magic link seems correct (redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F%23%2Fsandbox), it is ignored;
Instead, after a successful login (checked in Auth0 logs), the url in the address bar is (briefly):
http://localhost:3000/#access_token=xxxxxxxxxx&id_token=yyyyyyyyy&email=myemail#emails.com (notice the # instead of expected question mark)
then (after a second or so) it redirects to: http://localhost:3000/#/access_token
My questions are:
How to have Auth0 actually redirect to callbackURL?
How can I catch the token with the new angular2 router, even though the uri is misformed? (question mark missing before the query)
After much struggling, I found a workaround.
TL;DR; use PathLocationStrategy (HTML 5 pushState), not the "hash URL" style.
Below Allowed logout URLs and Allowed origins in the Auth0 console (Clients settings), it is specified:
Notice that querystrings and hash information are not taken into account when validating these URLs.
So I figured it might apply to Allowed Callback URLs as well, even though it was not specified.
That would explain why callbackURL is ignored.
The trick is then to get rid of the hash (#) in the URLs; the hash is the default LocationStrategy in Angular2 Webpack Starter.
To do that, in app.modules.ts, change RouterModule.forRoot(ROUTES, { useHash: true }) to RouterModule.forRoot(ROUTES, { useHash: false })
Although it should have worked, I came accross yet another issue: when you reload a page, it gives a blank page with the following message:
<% if (webpackConfig.htmlElements.headTags) { %>
After a little Googling, I found a fix in this page.
The fix is to remove the carret (^) in the "webpack-dev-server": "^2.1.0-beta.2" (devDependencies, package.json), and reinstall the package:
replace "^2.1.0-beta.2" by "2.1.0-beta.2"
then, in console/terminal, type: npm install webpack-dev-server
Now all I had to do was to update the callbackURL like so:
this.lock.magiclink({
callbackURL:"http://localhost:3000/sandbox"
});
And in Auth0 Clients settings' Allowed Callback URLs, insert:
http://localhost:3000/sandbox
and save.
Now, after a successful login (when I click the magic link in the e-mail), it opens a browser window with following URL:
http://localhost:3000/sandbox#access_token=xxxxxxxxxxx&id_token=yyyyyyyyyyy&token_type=Bearer
and it stays there, as it should. Catching and saving the token should now be trivial...

Admin Tools config throws 404: page not found

I try to setup the basic configuration of admin tools and fail with the url dispatcher recognizing the include of admin_tools.urls:
#urls.py
...
import admin_tools.urls
urlpatterns = patterns('',
url(r'^admintools/', include(admin_tools.urls)),
url(r'^admin/', include(admin.site.urls)),
)
#settings.py
import django.conf.global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
"django.core.context_processors.request",
)
INSTALLED_APPS = (
'django.contrib.auth',
...
'admin_tools',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'repmgr',)
I did run syncdb. I am sure that the regexp matches /admintools/, because it works when I include another app.
The detailed error response is:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admintools/
Using the URLconf defined in urlconf, Django tried these URL patterns, in this order:
^__debug__/m/(.*)$
^__debug__/sql_select/$ [name='sql_select']
^__debug__/sql_explain/$ [name='sql_explain']
^__debug__/sql_profile/$ [name='sql_profile']
^__debug__/template_source/$ [name='template_source']
^admin/doc/
^admintools/ ^menu/
^admintools/ ^dashboard/
^sthrep/
The current URL, admintools/, didn't match any of these.
The error message is perfectly correct :
Django tells that there is no URL pattern matching ^admintools/^. That is true. This is because django-admin-tools does not create a different admin site, but rather extends the original admin site.
The ^admintools/ pattern is only created for its sub-patterns, that provide access to pages needed by admin-tools to work well (new pages added to the original admin, for example).
By the way, in django-admin-tools documentation, at the end of the setup instructions, they say :
Congrats! At this point you should have a working installation of
django-admin-tools. Now you can just login to your admin site and see
what changed.
I guess that by your admin site they mean the standard admin site.
So I think that the good way to access your admin interface and menus and dashboards is using the standard admin.

MalformedURLException in application tests

I'm working on application tests and have found an issue.
My app. has an authenticate(email, password) action inside the
Security controller and when invoked, from the login page, with a
valid e-mail and invalid password it sends me back to the login page
with an error message, located in the flash scope.
The app. test code follows :
Response response =
GET("/security/authenticate?email=validUser&password=invalid", true);
String pattern = "invalid password";
assertContentMatch(pattern, response);
When this code is run throws the next exception :
A java.lang.RuntimeException has been caught,
java.net.MalformedURLException: no protocol: /login
Did some research and found that :
the exception is thrown when a new URL object creation is attempted,
to be able for redirection, using an invalid URL. In this case no
protocol is present
looking at app. test in samples apps. GET is used without
redirection, meaning that after GET only the http code is verified but
no attempt to follow the redirection
Has anyone had this same issue also ?
Any open bug to look for info or add my 2 cents ?
Here you can find a description of the problem as well as code snippet to work around the issue:
https://play.lighthouseapp.com/projects/57987/tickets/1553-functionaltestget-with-redirect-crashes