Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRST-2676: added emailPasswordSHA256 and passwordSHA1SHA256 #113

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/ravelin/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

module Ravelin
class Password < RavelinObject
attr_accessor :success, :failure_reason, :password_hashed
attr_accessor :success, :failure_reason, :password_hashed, :emailPasswordSHA256, :passwordSHA1SHA256
attr_required :success

# Alternative interface, because when the attr is called "password_hashed",
# the end user might think they need to hash the password themselves
def password=(passwd)
@password_hashed = Digest::SHA256.hexdigest(passwd)
@passwordSHA1SHA256 = Digest::SHA256.hexdigest(Digest::SHA1.hexdigest(passwd))
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
end

def password_hashed=(passwd)
@password_hashed = passwd
end

def emailPassword=(emailPassword)
@emailPasswordSHA256 = Digest::SHA256.hexdigest(emailPassword)
end

def passwordSHA1SHA256=(passwd)
@passwordSHA1SHA256 = Digest::SHA256.hexdigest(Digest::SHA1.hexdigest(passwd))
Dismissed Show dismissed Hide dismissed
end

FAILURE_REASONS = %w(BAD_PASSWORD UNKNOWN_USERNAME AUTHENTICATION_FAILURE INTERNAL_ERROR RATE_LIMIT BANNED_USER)

def validate
Expand Down
2 changes: 1 addition & 1 deletion lib/ravelin/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Ravelin
VERSION = '0.1.48'
VERSION = '0.1.49'
end
13 changes: 10 additions & 3 deletions spec/ravelin/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class MyDummyClass < Ravelin::RavelinObject
authentication_mechanism: {
password: {
password: 'super-secret-password',
success: true
success: true,
emailPassword: '[email protected]',
}
}
}
Expand Down Expand Up @@ -237,7 +238,9 @@ class MyDummyClass < Ravelin::RavelinObject
'authenticationMechanism' => {
'password' => {
'passwordHashed' => '5c76fcf4400da3b4804d70b91af20703d483f2c5860cc2f8d59592a1da8d2121',
'success' => true
'success' => true,
'emailPasswordSHA256' => '60b980431585b5ec81dffba0dc11cf44b583d8925924af5f71d756404ef2e0a7',
'passwordSHA1SHA256' => '8f8db8a623009b56dc4ed8c47ede9d6a72d7569dcdfcedd6c1b7a3f441719f67',
}
},
'customerId' => '123',
Expand Down Expand Up @@ -268,6 +271,7 @@ class MyDummyClass < Ravelin::RavelinObject
authentication_mechanism: {
password: {
password: 'super-secret-password',
emailPassword: '[email protected]',
success: true
}
}
Expand Down Expand Up @@ -303,13 +307,16 @@ class MyDummyClass < Ravelin::RavelinObject
timestamp: 1586283630
).serializable_hash

puts output
expect(output).to eq(
{
"login" => {
"authenticationMechanism" => {
"password" => {
"passwordHashed" => "5c76fcf4400da3b4804d70b91af20703d483f2c5860cc2f8d59592a1da8d2121",
"success" => true
"success" => true,
'emailPasswordSHA256' => '60b980431585b5ec81dffba0dc11cf44b583d8925924af5f71d756404ef2e0a7',
'passwordSHA1SHA256' => '8f8db8a623009b56dc4ed8c47ede9d6a72d7569dcdfcedd6c1b7a3f441719f67',
}
},
"customerId" => "123",
Expand Down
7 changes: 6 additions & 1 deletion spec/ravelin/login_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'digest'

describe Ravelin::Login do
subject do
Expand All @@ -10,7 +11,8 @@
authentication_mechanism: {
password: {
password: "lol",
success: true
success: true,
emailPassword: "[email protected]",
}
},
custom: {
Expand All @@ -22,6 +24,9 @@

context 'creates instance with valid params' do
it { expect { subject }.to_not raise_exception }

it { expect(subject.authentication_mechanism.password.emailPasswordSHA256).to eq('53437119eca797b8110d9299142f7b123aa011ef6676905ce30bbc887cec7efc') }
it { expect(subject.authentication_mechanism.password.passwordSHA1SHA256).to eq('539424f5201711772633efc0ccbaefa3e946e666bf4cc6a7a7ff0451826ba824') }
end

context 'creates an authentication_mechanism object' do
Expand Down