Skip to content

Commit 0892e54

Browse files
committed
🚨 Linting
1 parent 9f51014 commit 0892e54

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

.rubocop_gradual.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
"app/controllers/masq/sessions_controller.rb:3600302919": [
99
[39, 21, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806]
1010
],
11-
"app/models/masq/persona.rb:3585878101": [
12-
[14, 5, 55, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1041090622],
13-
[18, 5, 142, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3038409932],
14-
[55, 5, 3, "Lint/IneffectiveAccessModifier: `private` (on line 52) does not make singleton methods private. Use `private_class_method` or `private` inside a `class << self` block instead.", 193404514],
15-
[55, 5, 78, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2563415249]
16-
],
17-
"app/models/masq/signup.rb:1186383472": [
18-
[7, 5, 126, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1071524745]
19-
],
2011
"lib/masq/authenticated_system.rb:2956957840": [
2112
[95, 5, 3, "Lint/IneffectiveAccessModifier: `protected` (on line 3) does not make singleton methods protected. Use `protected` inside a `class << self` block instead.", 193404514],
2213
[95, 5, 111, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 4258707989],

app/models/masq/account.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Account < ActiveRecord::Base
2424
after_save :deliver_forgot_password
2525

2626
# attr_accessible :login, :email, :password, :password_confirmation, :public_persona_id, :yubikey_mandatory
27-
attr_accessor :password, :password_confirmation
27+
attr_accessor :password
2828

2929
class ActivationCodeNotFound < StandardError; end
3030

@@ -53,7 +53,7 @@ def find_and_activate!(activation_code)
5353
# Authenticates a user by their login name and password.
5454
# Returns the user or nil.
5555
def authenticate(login, password, basic_auth_used = false)
56-
a = Account.find_by(login: login)
56+
a = find_by(login: login)
5757
if a.nil? && Masq::Engine.config.masq["create_auth_ondemand"]["enabled"]
5858
# Need to set some password - but is never used
5959
pw = if Masq::Engine.config.masq["create_auth_ondemand"]["random_password"]
@@ -72,7 +72,8 @@ def authenticate(login, password, basic_auth_used = false)
7272

7373
if !a.nil? && a.active? && a.enabled
7474
if a.authenticated?(password) || (Masq::Engine.config.masq["trust_basic_auth"] && basic_auth_used)
75-
a.last_authenticated_at, a.last_authenticated_by_yubikey = Time.now, a.authenticated_with_yubikey?
75+
a.last_authenticated_at = Time.now.utc
76+
a.last_authenticated_by_yubikey = a.authenticated_with_yubikey?
7677
a.save(validate: false)
7778
a
7879
end
@@ -144,15 +145,15 @@ def authenticated?(password)
144145
elsif password.length < 50 && !(yubico_identity? && yubikey_mandatory?)
145146
encrypt(password) == crypted_password
146147
elsif Masq::Engine.config.masq["can_use_yubikey"]
147-
password, yubico_otp = Account.split_password_and_yubico_otp(password)
148+
password, yubico_otp = self.class.split_password_and_yubico_otp(password)
148149
@authenticated_with_yubikey = yubikey_authenticated?(yubico_otp) if encrypt(password) == crypted_password
149150
end
150151
end
151152

152153
# Is the Yubico OTP valid and belongs to this account?
153154
def yubikey_authenticated?(otp)
154-
if yubico_identity? && Account.verify_yubico_otp(otp)
155-
(Account.extract_yubico_identity_from_otp(otp) == yubico_identity)
155+
if yubico_identity? && self.class.verify_yubico_otp(otp)
156+
(self.class.extract_yubico_identity_from_otp(otp) == yubico_identity)
156157
else
157158
false
158159
end
@@ -163,8 +164,8 @@ def authenticated_with_yubikey?
163164
end
164165

165166
def associate_with_yubikey(otp)
166-
if Account.verify_yubico_otp(otp)
167-
self.yubico_identity = Account.extract_yubico_identity_from_otp(otp)
167+
if self.class.verify_yubico_otp(otp)
168+
self.yubico_identity = self.class.extract_yubico_identity_from_otp(otp)
168169
save(validate: false)
169170
else
170171
false
@@ -238,7 +239,7 @@ def make_password_reset_code
238239
end
239240

240241
def deliver_forgot_password
241-
AccountMailer.forgot_password(self).deliver_now if recently_forgot_password?
242+
Masq::AccountMailer.forgot_password(self).deliver_now if recently_forgot_password?
242243
end
243244
end
244245
end

app/models/masq/persona.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ class Persona < ActiveRecord::Base
1111

1212
# attr_protected :account_id, :deletable
1313

14-
def self.properties
15-
Persona.mappings.keys
16-
end
14+
class << self
15+
def properties
16+
mappings.keys
17+
end
18+
19+
def attribute_name_for_type_uri(type_uri)
20+
prop = mappings.detect { |i| i[1].include?(type_uri) }
21+
prop ? prop[0] : nil
22+
end
1723

18-
def self.attribute_name_for_type_uri(type_uri)
19-
prop = mappings.detect { |i| i[1].include?(type_uri) }
20-
prop ? prop[0] : nil
24+
# Mappings for SReg names and AX Type URIs to attributes
25+
def mappings
26+
Masq::Engine.config.masq["attribute_mappings"]
27+
end
2128
end
2229

30+
public
31+
2332
# Returns the personas attribute for the given SReg name or AX Type URI
2433
def property(type)
2534
prop = Persona.mappings.detect { |i| i[1].include?(type) }
@@ -48,12 +57,5 @@ def date_of_birth=(dob)
4857
def check_deletable!
4958
raise ActiveRecord::RecordNotDestroyed unless deletable
5059
end
51-
52-
private
53-
54-
# Mappings for SReg names and AX Type URIs to attributes
55-
def self.mappings
56-
Masq::Engine.config.masq["attribute_mappings"]
57-
end
5860
end
5961
end

app/models/masq/site.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Site < ActiveRecord::Base
1010

1111
# Sets the release policies by first deleting the old ones and
1212
# then appending a new one for every given sreg and ax property.
13-
# This setter is used to set the attributes recieved from the
13+
# This setter is used to set the attributes received from the
1414
# update site form, so it gets passed AX and SReg properties.
1515
# To be backwards compatible (SReg seems to be obsolete now that
1616
# there is AX), SReg properties get a type_identifier matching
@@ -53,7 +53,7 @@ def sreg_properties
5353
end
5454

5555
# Returns a hash with all released AX properties.
56-
# AX properties have an URL as type_identifier.
56+
# AX properties have a URL as type_identifier.
5757
def ax_properties
5858
props = {}
5959
release_policies.each do |rp|

test/functional/masq/sessions_controller_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def test_should_authenticate_with_password_and_yubico_otp
123123
yubico_otp = @account.yubico_identity + "x" * 32
124124
Account.expects(:verify_yubico_otp).with(yubico_otp).returns(true)
125125
post(:create, params: {login: @account.login, password: "test" + yubico_otp})
126-
sleep(1) # Somehow the reload frequently occurred before the record change had been saved
127126
@account.reload
128127
assert_not_nil(@account.last_authenticated_at)
129128
assert(@account.last_authenticated_by_yubikey)

0 commit comments

Comments
 (0)