2016-06-06 00:53:27 -04:00
|
|
|
class FakeU2fDevice
|
2016-08-16 15:16:15 -04:00
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def initialize(page, name)
|
2016-06-06 00:53:27 -04:00
|
|
|
@page = page
|
2016-08-16 15:16:15 -04:00
|
|
|
@name = name
|
2016-06-06 00:53:27 -04:00
|
|
|
end
|
2016-12-24 11:53:13 -05:00
|
|
|
|
2016-06-06 00:53:27 -04:00
|
|
|
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-07-11 03:32:24 -04:00
|
|
|
challenge = @page.evaluate_script('gon.u2f.challenge')
|
|
|
|
json_response = u2f_device(app_id).sign_response(challenge)
|
2016-06-06 00:53:27 -04:00
|
|
|
|
|
|
|
@page.execute_script("
|
|
|
|
u2f.sign = function(appId, challenges, signRequests, callback) {
|
|
|
|
callback(#{json_response});
|
|
|
|
};
|
2016-12-24 11:53:13 -05:00
|
|
|
window.gl.u2fAuthenticate.start();
|
2016-06-06 00:53:27 -04:00
|
|
|
")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def u2f_device(app_id)
|
|
|
|
@u2f_device ||= U2F::FakeU2F.new(app_id)
|
|
|
|
end
|
|
|
|
end
|