-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from amratab/authentication_support
Authentication support
- Loading branch information
Showing
3 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,19 @@ In your test: | |
StripeTester.stripe_version = "2015-10-16" | ||
``` | ||
|
||
4. Send the webhook. This will send a POST request to the URL with the event data as JSON: | ||
4. If you are using username and password in your stripe webhook event, you can provide it in two ways. | ||
```ruby | ||
StripeTester.webhook_password = "<password>" | ||
or | ||
you can set it in your webhook_url itself like this | ||
# Normal HTTP URL | ||
StripeTester.webhook_url = "http://stripe:[email protected]/my_post_url" | ||
|
||
# HTTPS URL | ||
StripeTester.webhook_url = "https://stripe:[email protected]/my_post_url" | ||
``` | ||
|
||
5. Send the webhook. This will send a POST request to the URL with the event data as JSON: | ||
```ruby | ||
# as a symbol | ||
StripeTester.create_event(:invoice_created) | ||
|
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
after(:each) do | ||
StripeTester.stripe_version = nil | ||
StripeTester.verify_ssl = nil | ||
StripeTester.webhook_password = nil | ||
end | ||
|
||
describe "#load_template" do | ||
|
@@ -74,6 +75,23 @@ | |
expect(result_url.to_s).to eq(url) | ||
end | ||
|
||
it "#webhook_url should set the correct url if authentication is provided in url itself" do | ||
url = 'http://abc:[email protected]' | ||
StripeTester.webhook_url = url | ||
|
||
result_url = StripeTester.webhook_url | ||
expect(result_url.to_s).to eq(url) | ||
end | ||
|
||
it "#webhook_url should have correct url when password is provided through webhook_password" do | ||
url = 'http://www.google.com' | ||
StripeTester.webhook_url = url | ||
StripeTester.webhook_password = 'password' | ||
|
||
result_url = StripeTester.webhook_url | ||
expect(result_url.to_s).to eq(url) | ||
end | ||
|
||
it "#verify_ssl should default to true" do | ||
result_verify = StripeTester.verify_ssl? | ||
expect(result_verify).to eq(true) | ||
|
@@ -114,6 +132,38 @@ | |
expect(response).to be_truthy | ||
end | ||
|
||
it "#post_to_url should return true when authentication is provided" do | ||
data = StripeTester.load_template(:invoice_created) | ||
url = "http://localhost:3000/transactions" | ||
fake_web_url = "http://stripe:password@localhost:3000/transactions" | ||
StripeTester.webhook_url = url | ||
StripeTester.webhook_password='password' | ||
|
||
FakeWeb.register_uri(:post, | ||
fake_web_url, | ||
body: data.to_json, | ||
content_type: 'application/json') | ||
|
||
response = StripeTester.post_to_url(data) | ||
|
||
expect(response).to be_truthy | ||
end | ||
|
||
it "#post_to_url should return true when authentication is provided through url" do | ||
data = StripeTester.load_template(:invoice_created) | ||
url = "http://stripe:password@localhost:3000/transactions" | ||
StripeTester.webhook_url = url | ||
|
||
FakeWeb.register_uri(:post, | ||
url, | ||
body: data.to_json, | ||
content_type: 'application/json') | ||
|
||
response = StripeTester.post_to_url(data) | ||
|
||
expect(response).to be_truthy | ||
end | ||
|
||
it "#post_to_url should raise an error when request fails" do | ||
data = StripeTester.load_template(:invoice_created) | ||
url = "http://localhost:3000/" | ||
|