2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
class FakeU2fDevice
|
2016-09-13 17:45:13 +05:30
|
|
|
attr_reader :name
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def initialize(page, name, device = nil)
|
2016-06-16 23:09:34 +05:30
|
|
|
@page = page
|
2016-09-13 17:45:13 +05:30
|
|
|
@name = name
|
2020-11-24 15:15:51 +05:30
|
|
|
@u2f_device = device
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def respond_to_u2f_registration
|
|
|
|
app_id = @page.evaluate_script('gon.u2f.app_id')
|
|
|
|
challenges = @page.evaluate_script('gon.u2f.challenges')
|
|
|
|
|
|
|
|
json_response = u2f_device(app_id).register_response(challenges[0])
|
|
|
|
|
|
|
|
@page.execute_script("
|
|
|
|
u2f.register = function(appId, registerRequests, signRequests, callback) {
|
|
|
|
callback(#{json_response});
|
|
|
|
};
|
|
|
|
")
|
|
|
|
end
|
|
|
|
|
|
|
|
def respond_to_u2f_authentication
|
|
|
|
app_id = @page.evaluate_script('gon.u2f.app_id')
|
2016-08-24 12:49:21 +05:30
|
|
|
challenge = @page.evaluate_script('gon.u2f.challenge')
|
|
|
|
json_response = u2f_device(app_id).sign_response(challenge)
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
@page.execute_script("
|
|
|
|
u2f.sign = function(appId, challenges, signRequests, callback) {
|
|
|
|
callback(#{json_response});
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
window.gl.u2fAuthenticate.start();
|
2016-06-16 23:09:34 +05:30
|
|
|
")
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def fake_u2f_authentication
|
|
|
|
@page.execute_script("window.gl.u2fAuthenticate.renderAuthenticated('abc');")
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def u2f_device(app_id)
|
|
|
|
@u2f_device ||= U2F::FakeU2F.new(app_id)
|
|
|
|
end
|
|
|
|
end
|