This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added browser.authenticate for http basic authentication
- Loading branch information
1 parent
6535c1b
commit 5b5067f
Showing
9 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "Authenticate.h" | ||
#include "WebPage.h" | ||
#include "NetworkAccessManager.h" | ||
|
||
Authenticate::Authenticate(WebPageManager *manager, QStringList &arguments, QObject *parent) : Command(manager, arguments, parent) { | ||
} | ||
|
||
void Authenticate::start() { | ||
QString username = arguments()[0]; | ||
QString password = arguments()[1]; | ||
|
||
NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager()); | ||
networkAccessManager->setUserName(username); | ||
networkAccessManager->setPassword(password); | ||
|
||
emit finished(new Response(true)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "Command.h" | ||
|
||
class WebPage; | ||
|
||
class Authenticate : public Command { | ||
Q_OBJECT | ||
|
||
public: | ||
Authenticate(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); | ||
virtual void start(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5b5067f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will setting authentication persist for an entire test run, or will capybara-webkit reset it for each example? Can I unauthenticate? If the challenge fails, what happens?
5b5067f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently I don't think it's being reset so it will persist. No you cannot unauthenticate with this commit. If the challenge fails it up to the application to return a response so it depends on what type of response your app will return. The typical response to return on a failed authentication is a 403, returning a 401 will cause an infinite loop since that would be asking for authentication again. I currently don't have a guard in for such a scenario.
5b5067f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the question of unauthenticating... how would you unauthenticate using a normal browser... that doesn't seem like a concern for an integration test.
5b5067f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In between tests it will be reset. You may however see the following header:
HTTP_AUTHORIZATION: Basic Og==
Which is what would happen if you tried to authorize with an empty username and password.
5b5067f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does one access the browser object? I'm seeing this error
undefined local variable or method `browser' for #RSpec::Core::ExampleGroup::Nested_2::Nested_2:0xbfa62ec
for this code https://gist.github.com/2963178