Laravel 8 Dusk: testing login using Jetstream and Inertia JS is not working - laravel-dusk

I am working on a Laravel 8 project. I have noticed that a couple of things have changed in the Laravel 8 including authentication. I am using Jetstream and Intertia JS for authentication and admin panel. I am now having trouble writing Browser test using Dusk for login. It seems to be that the login is not working in the test even though it is actually working.
This is my test
function test userCanLogin()
{
$this->browse(function (Browser $browser) {
$admin = User::factory()->create();//I make sure that the password is Test.1234 and I can login on the browser.
$browser->visit('/login')->type('email', $admin->email)
->type('password', 'Test.1234')
->press('Login')
->assertAuthenticatedAs($admin);
});
}
When I run the test, I am getting the following error.
The currently authenticated user is not who was expected.
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
## ##
-Array &0 (
- 'id' => 1
- 'className' => 'App\Models\User'
-)
+Array &0 ()
What is wrong with my code and how can I fix it?

I'm not 100% sure but I think by default Dusk waits for a page refresh before doing asserts. Since Inertia is loading via JS you need to either explicitly pause() or waitFor() some element that would indicate that the page has been loaded. (See Dusk docs on waiting)
There's also this library that adds events to Inertia.js that you can listen for in Dusk

Related

onAuthRequired triggering only once in Chrome version > 72

In our project we are using Selenium to test our Angular Web Application using a docker image and chrome with version 70.0.3538.77 (Official Build) (64-bit). Since the application uses basic authentication on our servers we created our own extension to listen to "onAuthRequired" and whenever this happens we return the username and password (Original Source).
A simple test for our application would be to navigate to the main page (basic auth login required with the popup window) and then to another subpage that is hosted inside of this page in an iframe where the basic authentication is required again.
We added some logging to the extension just to check whether the onAuthRequired gets triggered so the extension currently looks like this:
​if (!chrome.webRequest.onAuthRequired.hasListener(retrieveCredentials)) {
chrome.webRequest.onAuthRequired.addListener(
retrieveCredentials,
{urls: ["<all_urls>"]},
['blocking']
);
}
function retrieveCredentials(details) {
console.log("onAuthRequired");
return {
authCredentials: {
username: username,
password: password
}
};
}
What we found out is that with the Version 72.0.3626 this was still working. The extension would fill out both of the login prompts that occur and we would see two messages with "onAuthRequired" in the console.
However with the Version 73.0.3683 and newer, this seems to not work anymore. Only one time the onAuthRequired (retrieveCredentials-Method) is called and the second popup gets ignored by the extension. This lets the Selenium tests fail with a timeout exception since the navigation doesn't work anymore.
Does anyone know how to handle this in the newer Versions of Chrome or sees a mistake that we made in our extension?
Any help appreciated

Codeception Acceptance and Phantomjs Cookies outside your domain (Google oAuth)

I am at a crossroad where I have the "solution" but I am not sure its the best approach.
Part of my application is oAuth login and I want to test that too (Acceptance).
I have bogus accounts for my oAuth providers that i'll be using to Login. Problem is Cookies.
I am using Phantomjs. Even if I use clear_cookies: true on my yml file I have this problem where my test cannot login because Google remembers me.
The test is quite simple:
public function login_with_oauth(AcceptanceTester $I)
{
$I->amOnPage('/auth/logout');
$I->amOnPage('/');
$I->click(['id' => 'login']);
$I->click(['id' => 'btn_login_google']);
#$I->fillField(['id' => 'Email'], $this->login);
$I->fillField(['id' => 'Passwd'], $this->password);
$I->click(['id' => 'signIn']);
$I->waitForText($this->name);
$I->seeInCurrentUrl('/home');
}
First time it works, second it does not because Google remembers the logged in user so it doesnt show the login and password boxes anymore.
If I hit the google logout url (accounts.google.com/logout) it logs the user out, but the next time I try to login it will remember my EMAIL (thus not my password), the email field will be greyed out (disabled) so Codeception can't fill it and goes bananas.
Even if clear_cookies: true worked I would run into a problem where, for all my other test Cests that share the same Session, I would have to login _before(), which would add about 20% more time to run the tests.
The solution I've came up with: is to simply restart phantom before each test. Since phantom is managed by supervisord it is as easy as having a alias in my ~/bashrc, like so:
alias codecept=' supervisorctl stop phantomjs && supervisorctl start phantomjs && vendor/bin/codecept'
That way I can keep my cookies between each test and I can make sure my oAuth providers cookies are also cleared.
I also tried restarting phantom from within php on the __construct of the oAuth cest but that makes Codecept throw some weird errors.
Any ideas?
Thanks and best regards.

Meteor: setup accounts-github not working

I'm trying to setup authentication using github.
I followed the documentation. I've installed the packages:
$> meteor add accounts-github
$> meteor add service-configuration
And my code in server/github.js looks like:
ServiceConfiguration.configurations.remove({
service: "github"
});
ServiceConfiguration.configurations.insert({
service: "github",
clientId: '****',
secret: '*************'
});
Meteor.loginWithGithub({
requestPermissions: ['user', 'public_repo']
}, function (err) {
if (err)
Session.set('errorMessage', err.reason || 'Unknown error');
});
When I start meteor now I get the following error:
/Users/me/.meteor/tools/5bf1690853/lib/node_modules/fibers/future.js:173
throw(ex);
^
TypeError: Object #<Object> has no method 'loginWithGithub'
at app/server/github.js:11:8
at app/server/github.js:18:3
....
So it seems the Meteor object doesn't have the loginWithGithub method. Any suggestions why?
You are running the code in the /server directory of your app.
Usually you call this code from the web browser to make Meteor display the Github OAuth login dialog.
This is not available on the server since its only meant to work on the browser side. This is why you see this error.
You would usually fire Meteor.loginWithGithub() in the event listener for when they click a button or some UI element to begin the login process.
Another thing to keep in mind is Session (Session.get, Session.set, etc) only work on the client too.
To see which methods run where use the Meteor documentation. In the top corner of each method it shows where the code can run: Client, Server or Anywhere.

PhantomJS and jquery screen scraping - no output

I am attempting to do screen scraping using phantom js.
I have copied some phantomjs code from this site: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery
Starting with that script, I have modified into this: http://jsfiddle.net/dqfTa/ (see javascript)
My aim is to collect the prices from a website, which are the inner html of the ".price" tags, into a javascript array. Right now I am trying to console.log() them to my screen.
I am running phantomjs v1.6 and jquery v1.8 through the ubuntu 12.04 console. I am setting the user agent to "iPhone".
Here is my output:
nwo#aws-chaos-us-w-1:~/sandbox$ phantomjs usingjqueryandphantom.js
hello
success
============================================
Step "0"
============================================
It never gets past step 0. Take a look at my code, I did a console.log("h1"); but it won't output it. What am I doing wrong here?
Phantomjs requires you to hook into the console output coming from it's page context. From the API reference:
This callback is invoked when there is a JavaScript console message on
the web page. The callback may accept up to three arguments: the
string for the message, the line number, and the source identifier.
By default, console messages from the web page are not displayed.
Using this callback is a typical way to redirect it.
page.onConsoleMessage = function(msg) {
console.log("This message came from the webpage: "+ msg);
};

Login to Facebook Connect using JavaScript SDK freezes in Opera?

I have a Facebook Connect site under development. The login works great on Firefox, IE, Safari and Chrome. But when I test it using Opera (using the latest version = 11) I run into problems.
I get to the point where I get the login form pop-up, fill it in with my email and password and click the login button. After that the login window becomes empty and the window title says "XD Proxy".
I am using the Facebook Connect JavaScript SDK and there are some iFrames (displayed in the jQuery lightbox-style plugin "ColorBox") in my solution.
Do you know if there are problems with Opera and Facebook Connect, or if there's something in my code that causes this? As I said, the solution has been tested in all the other major browsers and work fine there.
Thanks in advance!
/Thomas
PS. On the development server I'm running the site on port number 8585. I've seen some posts on the net saying this can cause problems.
Facebook connect currently fails because Facebook's scripts "detect" Internet Explorer by checking if the attachEvent method is supported. Unfortunately, Opera supports this method (historically for compatibility with other sites that needed it). Now, if they only did this: https://github.com/facebook/connect-js/pull/240 ..
This broken pseudo-browser-detection causes the problem because Facebook happens to use some IE code that Opera does not support to embed Flash for cross-document messaging in the Flash-based part of the script, while the alternate window.postMessage() part of the script has other problems as described here: http://my.opera.com/hallvors/blog/2010/07/20/postmessage-s-targetorigin-and-security
I have found a solution that seems to work! If I add a channelUrl option to FB.init, I can log in. I got a warning from Opera saying the following:
Warning
http://www.yourdomain.com/channel.html?fb_xd_fragment
A page on the public Internet requests
data from your private intranet. For
security reasons, automatic access is
blocked, but you may choose to
continue.
LINK: Continue
LINK: Always continue when data is
requested from this server on my
private intranet
I clicked the link "Continue" and after that it worked (during this session). The original FB.init line looked like this (appId and some other stuff has been replaced in this example):
// Facebook init
FB.init({ appId: '123456789', status: true, cookie: true, xfbml: true });
After I had added the channelUrl it looked like this:
// Facebook init
FB.init({ appId: '123456789', status: true, cookie: true, xfbml: true, channelUrl: "http://www.yourdomain.com/channel.html" });
The file "channel.html" is a simple file that contains just this line of code:
<script src="http://connect.facebook.net/en_EN/all.js"></script>
Create it and put it on your server at the location you have specified in the channelUrl. The server root is a good place.
The next step is figuring out how to get rid of the Opera warning, if it's possible at all?
Good luck!
/Thomas Kahn
To fix it in Opera, just add the following after FB.init():
if($.browser.opera ) // it uses jQuery library here!
{
FB.XD._transport="postmessage";
FB.XD.PostMessage.init();
}
This channel.html dont work for me
<script src="http://connect.facebook.net/en_EN/all.js"></script>
but when I change it to:
<script src="http://connect.facebook.net/en_GB/all.js"></script>
it works. In this url is not valid content http://connect.facebook.net/en_EN/all.js there is something wr go to this instead http://connect.facebook.net/en_GB/all.js