diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-06-06 07:53:27 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-06-06 10:20:31 +0300 |
commit | 7232bdb9ad459147201d4ec5250465776168a62b (patch) | |
tree | 97775c809e0418c0c04205ec9e6fce1bf5766040 /spec/support | |
parent | 4db19bb4455cd21e80097a3e547d8b266a884aea (diff) |
Add feature specs covering U2F registration and authentication.
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 |