diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-06 17:46:36 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-06 17:46:36 +0300 |
commit | 3137a7fec37b7fb66ea464f4c5fdab964a73d390 (patch) | |
tree | 042228550ffc5f729a5358208c97283acf950721 /spec/support | |
parent | 842f0a3401de8d358fce850df288d9822e523c6e (diff) | |
parent | 13d4231eb9f577456b420ff5044c55584add9b39 (diff) |
Merge branch 'rename-ci-commit' into rename-ci-commit-phase-2
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/fake_u2f_device.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/support/fake_u2f_device.rb b/spec/support/fake_u2f_device.rb new file mode 100644 index 00000000000..553fe9f1fbc --- /dev/null +++ b/spec/support/fake_u2f_device.rb @@ -0,0 +1,36 @@ +class FakeU2fDevice + def initialize(page) + @page = page + end + + 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') + challenges = @page.evaluate_script('gon.u2f.challenges') + json_response = u2f_device(app_id).sign_response(challenges[0]) + + @page.execute_script(" + u2f.sign = function(appId, challenges, signRequests, callback) { + callback(#{json_response}); + }; + ") + end + + private + + def u2f_device(app_id) + @u2f_device ||= U2F::FakeU2F.new(app_id) + end +end |