Skip to content

Commit 9027e0a

Browse files
committed
Change test domains to use "example.com" wherever possible
Previously used domains like "blabla.com", "bla.com", and "bar.com" could exist in reality. Since IANA reserves example.com for documentation and examples, I replaced them with example.com whenever possible. The exception is test.host, which Rails uses as the default domain in tests (see: https://github.com/rails/rails/blob/d09c4bbfcadcd6b3af847a11608a63c0718158ed/actionpack/lib/action_dispatch/testing/test_request.rb#L11). Simply changing it to example.com causes tests to fail. While adding the following snippet to `spec_helper.rb` would make the tests pass, I decided to leave it as is since the motivation isn’t strong enough: ```ruby config.before(:each, type: :controller) do request.host = 'example.com' end ``` related url: Sorcery#387 (comment)
1 parent 22bff6e commit 9027e0a

11 files changed

+92
-92
lines changed

lib/sorcery/test_helpers/internal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def destroy
2424
end
2525

2626
def build_new_user(attributes_hash = nil)
27-
user_attributes_hash = attributes_hash || { username: 'gizmo', email: 'bla@bla.com', password: 'secret' }
27+
user_attributes_hash = attributes_hash || { username: 'gizmo', email: 'bla@example.com', password: 'secret' }
2828
@user = User.new(user_attributes_hash)
2929
end
3030

spec/controllers/controller_brute_force_protection_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'spec_helper'
22

33
describe SorceryController, type: :controller do
4-
let!(:user) { User.create!(username: 'test_user', email: 'bla@bla.com', password: 'password') }
4+
let!(:user) { User.create!(username: 'test_user', email: 'bla@example.com', password: 'password') }
55

66
def request_test_login
7-
get :test_login, params: { email: 'bla@bla.com', password: 'blabla' }
7+
get :test_login, params: { email: 'bla@example.com', password: 'blabla' }
88
end
99

1010
# ----------------- BRUTE FORCE PROTECTION -----------------------
@@ -20,7 +20,7 @@ def request_test_login
2020

2121
it 'counts login retries' do
2222
allow(User).to receive(:authenticate) { |&block| block.call(nil, :other) }
23-
allow(User.sorcery_adapter).to receive(:find_by_credentials).with(['bla@bla.com', 'blabla']).and_return(user)
23+
allow(User.sorcery_adapter).to receive(:find_by_credentials).with(['bla@example.com', 'blabla']).and_return(user)
2424

2525
expect(user).to receive(:register_failed_login!).exactly(3).times
2626

@@ -33,7 +33,7 @@ def request_test_login
3333

3434
allow(User).to receive(:authenticate) { |&block| block.call(user, nil) }
3535

36-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
36+
get :test_login, params: { email: 'bla@example.com', password: 'secret' }
3737

3838
user.reload
3939
expect(user.failed_logins_count).to eq(0)

spec/controllers/controller_http_basic_auth_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe SorceryController, type: :controller do
4-
let!(:user) { User.create!(username: 'test_user', email: 'bla@bla.com', password: 'password') }
4+
let!(:user) { User.create!(username: 'test_user', email: 'bla@example.com', password: 'password') }
55

66
describe 'with http basic auth features' do
77
before(:all) do
@@ -22,15 +22,15 @@
2222

2323
it 'authenticates from http basic if credentials are sent' do
2424
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:secret")}"
25-
expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
25+
expect(User).to receive('authenticate').with('bla@example.com', 'secret').and_return(user)
2626
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
2727

2828
expect(response).to be_successful
2929
end
3030

3131
it 'fails authentication if credentials are wrong' do
3232
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:wrong!")}"
33-
expect(User).to receive('authenticate').with('bla@bla.com', 'wrong!').and_return(nil)
33+
expect(User).to receive('authenticate').with('bla@example.com', 'wrong!').and_return(nil)
3434
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
3535

3636
expect(response).to redirect_to root_url
@@ -51,7 +51,7 @@
5151

5252
it "signs in the user's session on successful login" do
5353
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:secret")}"
54-
expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
54+
expect(User).to receive('authenticate').with('bla@example.com', 'secret').and_return(user)
5555

5656
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
5757

spec/controllers/controller_oauth2_spec.rb

Lines changed: 51 additions & 51 deletions
Large diffs are not rendered by default.

spec/controllers/controller_oauth_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# require 'shared_examples/controller_oauth_shared_examples'
44

55
def stub_all_oauth_requests!
6-
consumer = OAuth::Consumer.new('key', 'secret', site: 'http://myapi.com')
6+
consumer = OAuth::Consumer.new('key', 'secret', site: 'http://api.example.com')
77
req_token = OAuth::RequestToken.new(consumer)
88
acc_token = OAuth::AccessToken.new(consumer)
99

1010
response = Object.new
1111
def response.body
1212
{
1313
'following' => false, 'listed_count' => 0, 'profile_link_color' => '0084B4',
14-
'profile_image_url' => 'http://a1.twimg.com/profile_images/536178575/noamb_normal.jpg',
14+
'profile_image_url' => 'http://media.example.com/profile_images/536178575/noamb_normal.jpg',
1515
'description' => 'Programmer/Heavy Metal Fan/New Father',
1616
'status' => {
1717
'text' => 'coming soon to sorcery gem: twitter and facebook authentication support.',
@@ -27,7 +27,7 @@ def response.body
2727
'screen_name' => 'nbenari', 'profile_use_background_image' => true, 'location' => 'Israel',
2828
'statuses_count' => 25, 'profile_background_color' => '022330', 'lang' => 'en',
2929
'verified' => false, 'notifications' => false,
30-
'profile_background_image_url' => 'http://a3.twimg.com/profile_background_images/104087198/04042010339.jpg',
30+
'profile_background_image_url' => 'http://media.example.com/profile_background_images/104087198/04042010339.jpg',
3131
'favourites_count' => 5, 'created_at' => 'Fri Nov 20 21:58:19 +0000 2009',
3232
'is_translator' => false, 'contributors_enabled' => false, 'protected' => false,
3333
'follow_request_sent' => false, 'time_zone' => 'Greenland', 'profile_text_color' => '333333',
@@ -54,14 +54,14 @@ def response.body
5454
sorcery_controller_property_set(:external_providers, %i[twitter jira])
5555
sorcery_controller_external_property_set(:twitter, :key, 'eYVNBjBDi33aa9GkA3w')
5656
sorcery_controller_external_property_set(:twitter, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
57-
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com')
57+
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://example.com')
5858

5959
sorcery_controller_external_property_set(:jira, :key, '7810b8e317ebdc81601c72f8daecc0f1')
6060
sorcery_controller_external_property_set(:jira, :secret, 'MyAppUsingJira')
61-
sorcery_controller_external_property_set(:jira, :site, 'http://jira.mycompany.com/plugins/servlet/oauth')
61+
sorcery_controller_external_property_set(:jira, :site, 'http://jira.example.com/plugins/servlet/oauth')
6262
sorcery_controller_external_property_set(:jira, :signature_method, 'RSA-SHA1')
6363
sorcery_controller_external_property_set(:jira, :private_key_file, 'myrsakey.pem')
64-
sorcery_controller_external_property_set(:jira, :callback_url, 'http://myappusingjira.com/home')
64+
sorcery_controller_external_property_set(:jira, :callback_url, 'http://app.example.com/home')
6565
end
6666

6767
# ----------------- OAuth -----------------------
@@ -71,7 +71,7 @@ def response.body
7171
end
7272

7373
after do
74-
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com')
74+
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://example.com')
7575
sorcery_controller_external_property_set(:twitter, :original_callback_url, nil)
7676
end
7777

@@ -83,19 +83,19 @@ def response.body
8383
it 'login_at redirects correctly' do
8484
get :login_at_test
8585
expect(response).to be_a_redirect
86-
expect(response).to redirect_to('http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&oauth_token=')
86+
expect(response).to redirect_to('http://api.example.com/oauth/authorize?oauth_callback=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&oauth_token=')
8787
end
8888
end
8989

9090
context 'when callback_url begins with http://' do
9191
before do
92-
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com/oauth/twitter/callback')
92+
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://example.com/oauth/twitter/callback')
9393
end
9494

9595
it 'login_at redirects correctly' do
9696
get :login_at_test
9797
expect(response).to be_a_redirect
98-
expect(response).to redirect_to('http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com%2Foauth%2Ftwitter%2Fcallback&oauth_token=')
98+
expect(response).to redirect_to('http://api.example.com/oauth/authorize?oauth_callback=http%3A%2F%2Fexample.com%2Foauth%2Ftwitter%2Fcallback&oauth_token=')
9999
end
100100
end
101101

@@ -163,7 +163,7 @@ def response.body
163163
sorcery_model_property_set(:authentications_class, UserProvider)
164164

165165
allow(user).to receive_message_chain(:sorcery_config, :username_attribute_names, :first) { :username }
166-
allow(user).to receive(:username).and_return('bla@bla.com')
166+
allow(user).to receive(:username).and_return('bla@example.com')
167167
login_user(user)
168168

169169
expect(user).to receive(:add_provider_to_user).with('twitter', '123')

spec/controllers/controller_remember_me_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
end
1717

1818
it 'sets cookie on remember_me!' do
19-
expect(User).to receive(:authenticate).with('bla@bla.com', 'secret') { |&block| block.call(user, nil) }
19+
expect(User).to receive(:authenticate).with('bla@example.com', 'secret') { |&block| block.call(user, nil) }
2020
expect(user).to receive(:remember_me!)
2121

22-
post :test_login_with_remember, params: { email: 'bla@bla.com', password: 'secret' }
22+
post :test_login_with_remember, params: { email: 'bla@example.com', password: 'secret' }
2323

2424
expect(cookies.signed['remember_me_token']).to eq assigns[:current_user].remember_me_token
2525
end
@@ -39,11 +39,11 @@
3939
end
4040

4141
it 'login(email,password,remember_me) logs user in and remembers' do
42-
expect(User).to receive(:authenticate).with('bla@bla.com', 'secret', '1') { |&block| block.call(user, nil) }
42+
expect(User).to receive(:authenticate).with('bla@example.com', 'secret', '1') { |&block| block.call(user, nil) }
4343
expect(user).to receive(:remember_me!)
4444
expect(user).to receive(:remember_me_token).and_return('abracadabra').twice
4545

46-
post :test_login_with_remember_in_login, params: { email: 'bla@bla.com', password: 'secret', remember: '1' }
46+
post :test_login_with_remember_in_login, params: { email: 'bla@example.com', password: 'secret', remember: '1' }
4747

4848
expect(cookies.signed['remember_me_token']).not_to be_nil
4949
expect(cookies.signed['remember_me_token']).to eq assigns[:user].remember_me_token
@@ -76,13 +76,13 @@
7676
end
7777

7878
it 'doest not remember_me! when not asked to, even if third parameter is used' do
79-
post :test_login_with_remember_in_login, params: { email: 'bla@bla.com', password: 'secret', remember: '0' }
79+
post :test_login_with_remember_in_login, params: { email: 'bla@example.com', password: 'secret', remember: '0' }
8080

8181
expect(cookies['remember_me_token']).to be_nil
8282
end
8383

8484
it 'doest not remember_me! when not asked to' do
85-
post :test_login, params: { email: 'bla@bla.com', password: 'secret' }
85+
post :test_login, params: { email: 'bla@example.com', password: 'secret' }
8686
expect(cookies['remember_me_token']).to be_nil
8787
end
8888

spec/controllers/controller_session_timeout_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@
115115
it 'works if the session is stored as a string or a Time' do
116116
session[:login_time] = Time.now.to_s
117117
# TODO: ???
118-
expect(User).to receive(:authenticate).with('bla@bla.com', 'secret') { |&block| block.call(user, nil) }
118+
expect(User).to receive(:authenticate).with('bla@example.com', 'secret') { |&block| block.call(user, nil) }
119119

120-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
120+
get :test_login, params: { email: 'bla@example.com', password: 'secret' }
121121

122122
expect(session[:user_id]).not_to be_nil
123123
expect(response).to be_successful
@@ -129,7 +129,7 @@
129129
it 'does not logout if there was activity' do
130130
sorcery_controller_property_set(:session_timeout_from_last_action, true)
131131

132-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
132+
get :test_login, params: { email: 'bla@example.com', password: 'secret' }
133133
Timecop.travel(Time.now.in_time_zone + 0.3)
134134
get :test_should_be_logged_in
135135

@@ -144,7 +144,7 @@
144144

145145
it "with 'session_timeout_from_last_action' logs out if there was no activity" do
146146
sorcery_controller_property_set(:session_timeout_from_last_action, true)
147-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
147+
get :test_login, params: { email: 'bla@example.com', password: 'secret' }
148148
Timecop.travel(Time.now.in_time_zone + 0.6)
149149
get :test_should_be_logged_in
150150

spec/controllers/controller_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
describe '#login' do
5353
context 'when succeeds' do
5454
before do
55-
expect(User).to receive(:authenticate).with('bla@bla.com', 'secret') { |&block| block.call(user, nil) }
56-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
55+
expect(User).to receive(:authenticate).with('bla@example.com', 'secret') { |&block| block.call(user, nil) }
56+
get :test_login, params: { email: 'bla@example.com', password: 'secret' }
5757
end
5858

5959
it 'assigns user to @user variable' do
@@ -67,8 +67,8 @@
6767

6868
context 'when fails' do
6969
before do
70-
expect(User).to receive(:authenticate).with('bla@bla.com', 'opensesame!').and_return(nil)
71-
get :test_login, params: { email: 'bla@bla.com', password: 'opensesame!' }
70+
expect(User).to receive(:authenticate).with('bla@example.com', 'opensesame!').and_return(nil)
71+
get :test_login, params: { email: 'bla@example.com', password: 'opensesame!' }
7272
end
7373

7474
it 'sets @user variable to nil' do
@@ -154,7 +154,7 @@
154154

155155
it 'on successful login the user is redirected to the url he originally wanted' do
156156
session[:return_to_url] = 'http://test.host/some_action'
157-
post :test_return_to, params: { email: 'bla@bla.com', password: 'secret' }
157+
post :test_return_to, params: { email: 'bla@example.com', password: 'secret' }
158158

159159
expect(response).to redirect_to('http://test.host/some_action')
160160
expect(flash[:notice]).to eq 'haha!'

spec/shared_examples/user_brute_force_protection_shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
expect(lock_expires_at).not_to be_nil
108108

109109
Timecop.travel(Time.now.in_time_zone + 0.3)
110-
User.authenticate('bla@bla.com', 'secret')
110+
User.authenticate('bla@example.com', 'secret')
111111

112112
lock_expires_at = User.sorcery_adapter.find_by_id(user.id).lock_expires_at
113113
expect(lock_expires_at).to be_nil

spec/shared_examples/user_oauth_shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
sorcery_model_property_set(:authentications_class, Authentication)
1414
sorcery_controller_external_property_set(:twitter, :key, 'eYVNBjBDi33aa9GkA3w')
1515
sorcery_controller_external_property_set(:twitter, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
16-
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com')
16+
sorcery_controller_external_property_set(:twitter, :callback_url, 'http://example.com')
1717
end
1818

1919
it "responds to 'load_from_provider'" do

0 commit comments

Comments
 (0)