Skip to content

Commit 3ad9d76

Browse files
committed
🚨 More linting
1 parent a3da5f4 commit 3ad9d76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1731
-3828
lines changed

‎.rubocop_gradual.lock

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

‎Rakefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env rake
2-
require 'bundler/gem_tasks'
2+
require "bundler/gem_tasks"
33

4-
require 'rake/testtask'
4+
require "rake/testtask"
55

6-
desc 'Run tests'
7-
Rake::TestTask.new('test') do |t|
8-
t.libs << 'lib'
9-
t.libs << 'test'
10-
t.test_files = FileList['test/**/test_*.rb']
6+
desc "Run tests"
7+
Rake::TestTask.new("test") do |t|
8+
t.libs << "lib"
9+
t.libs << "test"
10+
t.test_files = FileList["test/**/test_*.rb"]
1111
t.verbose = false
1212
end
1313

1414
begin
15-
require 'rubocop/lts'
15+
require "rubocop/lts"
1616
Rubocop::Lts.install_tasks
1717
rescue LoadError
1818
task(:rubocop_gradual) do
19-
warn('RuboCop (Gradual) is disabled')
19+
warn("RuboCop (Gradual) is disabled")
2020
end
2121
end
2222

‎admin/mkassoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env ruby
22

3-
require 'openid/consumer/associationmanager'
4-
require 'openid/store/memory'
3+
require "openid/consumer/associationmanager"
4+
require "openid/store/memory"
55

66
store = OpenID::Store::Memory.new
77
ARGV.each do |server_url|
8-
unless URI::DEFAULT_PARSER.make_regexp =~ server_url
8+
unless URI::DEFAULT_PARSER.make_regexp&.match?(server_url)
99
puts "`#{server_url}` will be skipped for invalid URI format."
1010
next
1111
end
1212

1313
mgr = OpenID::Consumer::AssociationManager.new(store, server_url)
14-
puts '=' * 50
14+
puts "=" * 50
1515
puts "Server: #{server_url}"
1616
puts mgr.get_association.serialize
17-
puts '-' * 50
17+
puts "-" * 50
1818
end
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Use this migration to create the tables for the ActiveRecord store
22
class AddOpenIdStoreToDb < ActiveRecord::Migration
33
def self.up
4-
create_table 'open_id_associations', force: true do |t|
5-
t.column 'server_url', :string, null: false
6-
t.column 'handle', :string, null: false
7-
t.column 'secret', :binary, null: false
8-
t.column 'issued', :integer, null: false
9-
t.column 'lifetime', :integer, null: false
10-
t.column 'assoc_type', :string, null: false
4+
create_table("open_id_associations", force: true) do |t|
5+
t.column("server_url", :string, null: false)
6+
t.column("handle", :string, null: false)
7+
t.column("secret", :binary, null: false)
8+
t.column("issued", :integer, null: false)
9+
t.column("lifetime", :integer, null: false)
10+
t.column("assoc_type", :string, null: false)
1111
end
1212

13-
create_table 'open_id_nonces', force: true do |t|
14-
t.column :server_url, :string, null: false
15-
t.column :timestamp, :integer, null: false
16-
t.column :salt, :string, null: false
13+
create_table("open_id_nonces", force: true) do |t|
14+
t.column(:server_url, :string, null: false)
15+
t.column(:timestamp, :integer, null: false)
16+
t.column(:salt, :string, null: false)
1717
end
1818
end
1919

2020
def self.down
21-
drop_table 'open_id_associations'
22-
drop_table 'open_id_nonces'
21+
drop_table("open_id_associations")
22+
drop_table("open_id_nonces")
2323
end
2424
end

‎examples/active_record_openid_store/XXX_upgrade_open_id_store.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
# to the new 2.0 schema.
33
class UpgradeOpenIdStore < ActiveRecord::Migration
44
def self.up
5-
drop_table 'open_id_settings'
6-
drop_table 'open_id_nonces'
7-
create_table 'open_id_nonces', force: true do |t|
8-
t.column :server_url, :string, null: false
9-
t.column :timestamp, :integer, null: false
10-
t.column :salt, :string, null: false
5+
drop_table("open_id_settings")
6+
drop_table("open_id_nonces")
7+
create_table("open_id_nonces", force: true) do |t|
8+
t.column(:server_url, :string, null: false)
9+
t.column(:timestamp, :integer, null: false)
10+
t.column(:salt, :string, null: false)
1111
end
1212
end
1313

1414
def self.down
15-
drop_table 'open_id_nonces'
16-
create_table 'open_id_nonces', force: true do |t|
17-
t.column 'nonce', :string
18-
t.column 'created', :integer
15+
drop_table("open_id_nonces")
16+
create_table("open_id_nonces", force: true) do |t|
17+
t.column("nonce", :string)
18+
t.column("created", :integer)
1919
end
2020

21-
create_table 'open_id_settings', force: true do |t|
22-
t.column 'setting', :string
23-
t.column 'value', :binary
21+
create_table("open_id_settings", force: true) do |t|
22+
t.column("setting", :string)
23+
t.column("value", :binary)
2424
end
2525
end
2626
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# might using the ruby-openid gem
22
begin
3-
require 'rubygems'
3+
require "rubygems"
44
rescue LoadError
55
nil
66
end
7-
require 'openid'
8-
require 'openid_ar_store'
7+
require "openid"
8+
require "openid_ar_store"

‎examples/active_record_openid_store/lib/association.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'openid/association'
2-
require 'time'
1+
require "openid/association"
2+
require "time"
33

44
class Association < ActiveRecord::Base
5-
set_table_name 'open_id_associations'
5+
set_table_name "open_id_associations"
66
def from_record
77
OpenID::Association.new(handle, secret, Time.at(issued), lifetime, assoc_type)
88
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Nonce < ActiveRecord::Base
2-
set_table_name 'open_id_nonces'
2+
set_table_name "open_id_nonces"
33
end
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
require 'association'
2-
require 'nonce'
3-
require 'openid/store/interface'
1+
require "association"
2+
require "nonce"
3+
require "openid/store/interface"
44

55
# not in OpenID module to avoid namespace conflict
66
class ActiveRecordStore < OpenID::Store::Interface
77
def store_association(server_url, assoc)
88
remove_association(server_url, assoc.handle)
9-
Association.create!(server_url: server_url,
10-
handle: assoc.handle,
11-
secret: assoc.secret,
12-
issued: assoc.issued.to_i,
13-
lifetime: assoc.lifetime,
14-
assoc_type: assoc.assoc_type)
9+
Association.create!(
10+
server_url: server_url,
11+
handle: assoc.handle,
12+
secret: assoc.secret,
13+
issued: assoc.issued.to_i,
14+
lifetime: assoc.lifetime,
15+
assoc_type: assoc.assoc_type,
16+
)
1517
end
1618

1719
def get_association(server_url, handle = nil)
1820
assocs = if handle.blank?
19-
Association.find_all_by_server_url(server_url)
20-
else
21-
Association.find_all_by_server_url_and_handle(server_url, handle)
22-
end
21+
Association.find_all_by_server_url(server_url)
22+
else
23+
Association.find_all_by_server_url_and_handle(server_url, handle)
24+
end
2325

2426
if assocs.any?
25-
assocs.reverse.each do |assoc|
27+
assocs.reverse_each do |assoc|
2628
a = assoc.from_record
2729
return a unless a.expires_in.zero?
2830

@@ -34,7 +36,7 @@ def get_association(server_url, handle = nil)
3436
end
3537

3638
def remove_association(server_url, handle)
37-
Association.delete_all(['server_url = ? AND handle = ?', server_url, handle]) > 0
39+
Association.delete_all(["server_url = ? AND handle = ?", server_url, handle]) > 0
3840
end
3941

4042
def use_nonce(server_url, timestamp, salt)
@@ -47,11 +49,11 @@ def use_nonce(server_url, timestamp, salt)
4749

4850
def cleanup_nonces
4951
now = Time.now.to_i
50-
Nonce.delete_all(['timestamp > ? OR timestamp < ?', now + OpenID::Nonce.skew, now - OpenID::Nonce.skew])
52+
Nonce.delete_all(["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew])
5153
end
5254

5355
def cleanup_associations
5456
now = Time.now.to_i
55-
Association.delete_all(['issued + lifetime < ?', now])
57+
Association.delete_all(["issued + lifetime < ?", now])
5658
end
5759
end

‎examples/active_record_openid_store/test/store_test.rb

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
$:.unshift(File.dirname(__FILE__) + '/../lib')
2-
require 'test/unit'
3-
RAILS_ENV = 'test'
4-
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
1+
$:.unshift(File.dirname(__FILE__) + "/../lib")
2+
require "test/unit"
3+
RAILS_ENV = "test"
4+
require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment.rb"))
55

66
module StoreTestCase
77
@@allowed_handle = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
8-
@@allowed_nonce = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
8+
@@allowed_nonce = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
99

1010
def _gen_nonce
1111
OpenID::CryptUtil.random_string(8, @@allowed_nonce)
@@ -22,8 +22,13 @@ def _gen_secret(n, chars = nil)
2222
def _gen_assoc(issued, lifetime = 600)
2323
secret = _gen_secret(20)
2424
handle = _gen_handle(128)
25-
OpenID::Association.new(handle, secret, Time.now + issued, lifetime,
26-
'HMAC-SHA1')
25+
OpenID::Association.new(
26+
handle,
27+
secret,
28+
Time.now + issued,
29+
lifetime,
30+
"HMAC-SHA1",
31+
)
2732
end
2833

2934
def _check_retrieve(url, handle = nil, expected = nil)
@@ -40,11 +45,12 @@ def _check_retrieve(url, handle = nil, expected = nil)
4045

4146
def _check_remove(url, handle, expected)
4247
present = @store.remove_association(url, handle)
48+
4349
assert_equal(expected, present)
4450
end
4551

4652
def test_store
47-
server_url = 'http://www.myopenid.com/openid'
53+
server_url = "http://www.myopenid.com/openid"
4854
assoc = _gen_assoc(0)
4955

5056
# Make sure that a missing association returns no result
@@ -62,10 +68,10 @@ def test_store
6268
_check_retrieve(server_url, nil, assoc)
6369

6470
# Removing an association that does not exist returns not present
65-
_check_remove(server_url, assoc.handle + 'x', false)
71+
_check_remove(server_url, assoc.handle + "x", false)
6672

6773
# Removing an association that does not exist returns not present
68-
_check_remove(server_url + 'x', assoc.handle, false)
74+
_check_remove(server_url + "x", assoc.handle, false)
6975

7076
# Removing an association that is present returns present
7177
_check_remove(server_url, assoc.handle, true)
@@ -136,24 +142,26 @@ def test_store
136142
assoc_expired_2 = _gen_assoc(-7200, 3600)
137143

138144
@store.cleanup_associations
139-
@store.store_association(server_url + '1', assoc_valid_1)
140-
@store.store_association(server_url + '1', assoc_expired_1)
141-
@store.store_association(server_url + '2', assoc_expired_2)
142-
@store.store_association(server_url + '3', assoc_valid_2)
145+
@store.store_association(server_url + "1", assoc_valid_1)
146+
@store.store_association(server_url + "1", assoc_expired_1)
147+
@store.store_association(server_url + "2", assoc_expired_2)
148+
@store.store_association(server_url + "3", assoc_valid_2)
143149

144150
cleaned = @store.cleanup_associations
145-
assert_equal(2, cleaned, 'cleaned up associations')
151+
152+
assert_equal(2, cleaned, "cleaned up associations")
146153
end
147154

148-
def _check_use_nonce(nonce, expected, server_url, msg = '')
155+
def _check_use_nonce(nonce, expected, server_url, msg = "")
149156
stamp, salt = OpenID::Nonce.split_nonce(nonce)
150157
actual = @store.use_nonce(server_url, stamp, salt)
158+
151159
assert_equal(expected, actual, msg)
152160
end
153161

154162
def test_nonce
155-
server_url = 'http://www.myopenid.com/openid'
156-
[server_url, ''].each do |url|
163+
server_url = "http://www.myopenid.com/openid"
164+
[server_url, ""].each do |url|
157165
nonce1 = OpenID::Nonce.mk_nonce
158166

159167
_check_use_nonce(nonce1, true, url, "#{url}: nonce allowed by default")
@@ -175,23 +183,30 @@ def test_nonce
175183
@store.cleanup_nonces
176184
OpenID::Nonce.skew = 1_000_000
177185
ts, salt = OpenID::Nonce.split_nonce(old_nonce1)
178-
assert(@store.use_nonce(server_url, ts, salt), 'oldnonce1')
186+
187+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce1")
179188
ts, salt = OpenID::Nonce.split_nonce(old_nonce2)
180-
assert(@store.use_nonce(server_url, ts, salt), 'oldnonce2')
189+
190+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce2")
181191
ts, salt = OpenID::Nonce.split_nonce(recent_nonce)
182-
assert(@store.use_nonce(server_url, ts, salt), 'recent_nonce')
192+
193+
assert(@store.use_nonce(server_url, ts, salt), "recent_nonce")
183194

184195
OpenID::Nonce.skew = 1000
185196
cleaned = @store.cleanup_nonces
197+
186198
assert_equal(2, cleaned, "Cleaned #{cleaned} nonces")
187199

188200
OpenID::Nonce.skew = 100_000
189201
ts, salt = OpenID::Nonce.split_nonce(old_nonce1)
190-
assert(@store.use_nonce(server_url, ts, salt), 'oldnonce1 after cleanup')
202+
203+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce1 after cleanup")
191204
ts, salt = OpenID::Nonce.split_nonce(old_nonce2)
192-
assert(@store.use_nonce(server_url, ts, salt), 'oldnonce2 after cleanup')
205+
206+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce2 after cleanup")
193207
ts, salt = OpenID::Nonce.split_nonce(recent_nonce)
194-
assert(!@store.use_nonce(server_url, ts, salt), 'recent_nonce after cleanup')
208+
209+
assert(!@store.use_nonce(server_url, ts, salt), "recent_nonce after cleanup")
195210

196211
OpenID::Nonce.skew = orig_skew
197212
end

0 commit comments

Comments
 (0)