From c0bb2bb9b3ea605fc22b3647f6bdcf28631b617c Mon Sep 17 00:00:00 2001 From: Diego Barral Date: Thu, 14 Sep 2017 13:05:20 -0300 Subject: [PATCH] Reference fork of devise token auth instead of the gem --- Gemfile | 2 +- Gemfile.lock | 193 ++++++++++--------- spec/requests/api/v1/sessions/create_spec.rb | 52 ++++- 3 files changed, 156 insertions(+), 91 deletions(-) diff --git a/Gemfile b/Gemfile index 727c7c2d9..20c0c206f 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem 'carrierwave', '~> 0.11.2' gem 'carrierwave-base64', '~> 2.3.4' gem 'delayed_job_active_record', '~> 4.1.2' gem 'devise', '~> 4.3.0' -gem 'devise_token_auth', '~> 0.1.42' +gem 'devise_token_auth', github: 'rootstrap/devise_token_auth' gem 'draper', '~> 3.0.0' gem 'fog-aws', '~> 0.12.0' gem 'haml-rails', '~> 1.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index f999458ee..659877416 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,26 +1,34 @@ +GIT + remote: git://github.com/rootstrap/devise_token_auth.git + revision: c1bb7120a6be2c71c635a04aa12605347588bca1 + specs: + devise_token_auth (0.1.42) + devise (> 3.5.2, < 4.4) + rails (< 6) + GEM remote: https://rubygems.org/ specs: abstract_type (0.0.7) - actioncable (5.1.2) - actionpack (= 5.1.2) + actioncable (5.1.4) + actionpack (= 5.1.4) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.2) - actionpack (= 5.1.2) - actionview (= 5.1.2) - activejob (= 5.1.2) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.2) - actionview (= 5.1.2) - activesupport (= 5.1.2) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.2) - activesupport (= 5.1.2) + actionview (5.1.4) + activesupport (= 5.1.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -39,21 +47,20 @@ GEM ransack (~> 1.3) sass-rails sprockets (< 4.1) - activejob (5.1.2) - activesupport (= 5.1.2) + activejob (5.1.4) + activesupport (= 5.1.4) globalid (>= 0.3.6) - activemodel (5.1.2) - activesupport (= 5.1.2) - activemodel-serializers-xml (1.0.1) + activemodel (5.1.4) + activesupport (= 5.1.4) + activemodel-serializers-xml (1.0.2) activemodel (> 5.x) - activerecord (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.1.2) - activemodel (= 5.1.2) - activesupport (= 5.1.2) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) arel (~> 8.0) - activesupport (5.1.2) + activesupport (5.1.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) @@ -61,14 +68,15 @@ GEM adamantium (0.2.0) ice_nine (~> 0.11.0) memoizable (~> 0.4.0) - addressable (2.4.0) - annotate (2.6.5) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + annotate (2.6.7) activerecord (>= 2.3.0) - rake (>= 0.8.7) + rake (~> 10.4.2, >= 10.4.2) arbre (1.1.1) activesupport (>= 3.0.0) arel (8.0.0) - ast (2.0.0) + ast (2.3.0) astrolabe (1.3.1) parser (~> 2.2) bcrypt (3.1.11) @@ -81,23 +89,23 @@ GEM bourbon (4.3.4) sass (~> 3.4) thor (~> 0.19) - brakeman (3.4.0) + brakeman (3.4.1) builder (3.2.3) bullet (5.5.1) activesupport (>= 3.0.0) uniform_notifier (~> 1.10.0) - byebug (8.2.4) + byebug (8.2.5) carrierwave (0.11.2) activemodel (>= 3.2.0) activesupport (>= 3.2.0) json (>= 1.7) mime-types (>= 1.16) mimemagic (>= 0.3.0) - carrierwave-base64 (2.3.4) + carrierwave-base64 (2.3.5) carrierwave (>= 0.8.0) - code_analyzer (0.4.5) + code_analyzer (0.4.8) sexp_processor - coderay (1.1.1) + coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -112,7 +120,7 @@ GEM crack (0.4.3) safe_yaml (~> 1.0.0) database_cleaner (1.4.1) - debug_inspector (0.0.2) + debug_inspector (0.0.3) delayed_job (4.1.3) activesupport (>= 3.0, < 5.2) delayed_job_active_record (4.1.2) @@ -124,9 +132,6 @@ GEM railties (>= 4.1.0, < 5.2) responders warden (~> 1.2.3) - devise_token_auth (0.1.42) - devise (> 3.5.2, <= 4.3) - rails (< 6) diff-lcs (1.2.5) docile (1.1.5) draper (3.0.0) @@ -138,7 +143,7 @@ GEM equalizer (0.0.11) erubi (1.6.1) erubis (2.7.0) - excon (0.54.0) + excon (0.59.0) execjs (2.7.0) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -147,31 +152,31 @@ GEM railties (>= 3.0.0) faker (1.7.3) i18n (~> 0.5) - faraday (0.9.2) + faraday (0.13.1) multipart-post (>= 1.2, < 3) - ffi (1.9.14) + ffi (1.9.18) fog-aws (0.12.0) fog-core (~> 1.38) fog-json (~> 1.0) fog-xml (~> 0.1) ipaddress (~> 0.8) - fog-core (1.43.0) + fog-core (1.45.0) builder - excon (~> 0.49) + excon (~> 0.58) formatador (~> 0.2) fog-json (1.0.2) fog-core (~> 1.0) multi_json (~> 1.10) - fog-xml (0.1.2) + fog-xml (0.1.3) fog-core - nokogiri (~> 1.5, >= 1.5.11) + nokogiri (>= 1.5.11, < 2.0.0) formatador (0.2.5) formtastic (3.1.5) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) globalid (0.4.0) activesupport (>= 4.2.0) - haml (5.0.1) + haml (5.0.3) temple (>= 0.8.0) tilt haml-rails (1.0.0) @@ -183,13 +188,13 @@ GEM has_scope (0.7.1) actionpack (>= 4.1, < 5.2) activesupport (>= 4.1, < 5.2) - hashdiff (0.3.2) + hashdiff (0.3.6) html2haml (2.2.0) erubis (~> 2.7.0) haml (>= 4.0, < 6) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) - i18n (0.8.4) + i18n (0.8.6) ice_nine (0.11.2) inherited_resources (1.7.2) actionpack (>= 3.2, < 5.2.x) @@ -206,7 +211,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - json (1.8.3) + json (2.1.0) kaminari (1.0.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.0.1) @@ -242,8 +247,8 @@ GEM mime-types-data (3.2016.0521) mimemagic (0.3.2) mini_portile2 (2.2.0) - minitest (5.10.2) - multi_json (1.12.1) + minitest (5.10.3) + multi_json (1.12.2) multipart-post (2.0.0) nio4r (2.1.0) nokogiri (1.8.0) @@ -252,38 +257,43 @@ GEM orm_adapter (0.5.0) parser (2.2.2.6) ast (>= 1.1, < 3.0) - pg (0.18.2) + pg (0.18.4) polyamorous (1.3.1) activerecord (>= 3.0) powerpack (0.1.1) private_attr (1.1.0) procto (0.0.3) - pry (0.10.3) + pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-byebug (3.3.0) byebug (~> 8.0) pry (~> 0.10) - pry-rails (0.3.4) - pry (>= 0.9.10) - puma (3.6.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.0) + puma (3.10.0) rack (2.0.3) - rack-cors (0.4.0) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.1.2) - actioncable (= 5.1.2) - actionmailer (= 5.1.2) - actionpack (= 5.1.2) - actionview (= 5.1.2) - activejob (= 5.1.2) - activemodel (= 5.1.2) - activerecord (= 5.1.2) - activesupport (= 5.1.2) - bundler (>= 1.3.0, < 2.0) - railties (= 5.1.2) + rack-cors (0.4.1) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.2) + actionpack (~> 5.x, >= 5.0.1) + actionview (~> 5.x, >= 5.0.1) + activesupport (~> 5.x) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -297,30 +307,31 @@ GEM json require_all ruby-progressbar - railties (5.1.2) - actionpack (= 5.1.2) - activesupport (= 5.1.2) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.0.0) - rake (12.0.0) + rainbow (2.2.2) + rake + rake (10.4.2) ransack (1.8.3) actionpack (>= 3.0) activerecord (>= 3.0) activesupport (>= 3.0) i18n polyamorous (~> 1.3) - rb-fsevent (0.9.7) - rb-inotify (0.9.7) - ffi (>= 0.5.0) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) reek (3.4.1) parser (~> 2.2.2.5) private_attr (~> 1.1) rainbow (~> 2.0) unparser (~> 0.2.2) request_store (1.3.2) - require_all (1.3.3) + require_all (1.4.0) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) @@ -347,11 +358,15 @@ GEM powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) - ruby-progressbar (1.7.1) - ruby_parser (3.9.0) - sexp_processor (~> 4.1) + ruby-progressbar (1.8.3) + ruby_parser (3.10.1) + sexp_processor (~> 4.9) safe_yaml (1.0.4) - sass (3.4.24) + sass (3.5.1) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) @@ -360,16 +375,16 @@ GEM tilt (>= 1.1, < 3) sendgrid (1.2.4) json - sexp_processor (4.4.5) - shoulda-matchers (3.1.1) + sexp_processor (4.10.0) + shoulda-matchers (3.1.2) activesupport (>= 4.0.0) simplecov (0.13.0) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) - simplecov-html (0.10.0) + simplecov-html (0.10.2) slop (3.6.0) - spring (2.0.0) + spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -377,14 +392,14 @@ GEM sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) temple (0.8.0) - thor (0.19.4) + thor (0.20.0) thread_safe (0.3.6) - tilt (2.0.7) + tilt (2.0.8) tzinfo (1.2.3) thread_safe (~> 0.1) uglifier (2.7.2) @@ -424,7 +439,7 @@ DEPENDENCIES database_cleaner (~> 1.4.1) delayed_job_active_record (~> 4.1.2) devise (~> 4.3.0) - devise_token_auth (~> 0.1.42) + devise_token_auth! draper (~> 3.0.0) factory_girl_rails (~> 4.5.0) faker (~> 1.7.3) @@ -460,4 +475,4 @@ RUBY VERSION ruby 2.3.1p112 BUNDLED WITH - 1.14.2 + 1.15.1 diff --git a/spec/requests/api/v1/sessions/create_spec.rb b/spec/requests/api/v1/sessions/create_spec.rb index f558cbd69..ce61eb22b 100644 --- a/spec/requests/api/v1/sessions/create_spec.rb +++ b/spec/requests/api/v1/sessions/create_spec.rb @@ -2,7 +2,23 @@ describe 'POST api/v1/users/sign_in', type: :request do let(:password) { 'password' } - let(:user) { create(:user, password: password) } + let(:token) do + { '70crCAAYmNP1xLkKKM09zA' => + { + 'token' => '$2a$10$mSeRnpVMaaegCpn3AhORGe5wajFhgMoBjGIrMwq4Qq2mP6f/OHu1y', + 'expiry' => 153_574_356_4 + } + } + end + let(:token_as_string) do + "{ + \"70crCAAYmNP1xLkKKM09zA\": { + \"token\":\"$2a$10$mSeRnpVMaaegCpn3AhORGe5wajFhgMoBjGIrMwq4Qq2mP6f/OHu1y\", + \"expiry\":1535743564 + } + }" + end + let(:user) { create(:user, password: password, tokens: token) } context 'with correct params' do before do @@ -54,4 +70,38 @@ expect(json).to eq(expected_response) end end + + context 'with stringified tokens' do + before do + user.update_column(:tokens, token_as_string) + params = { + user: + { + email: user.email, + password: password + } + } + post new_user_session_path, params: params, as: :json + end + + it 'returns success' do + expect(response).to be_success + end + + it 'returns the user' do + expect(json[:user][:id]).to eq(user.id) + expect(json[:user][:email]).to eq(user.email) + expect(json[:user][:username]).to eq(user.username) + expect(json[:user][:uid]).to eq(user.uid) + expect(json[:user][:provider]).to eq('email') + expect(json[:user][:first_name]).to eq(user.first_name) + expect(json[:user][:last_name]).to eq(user.last_name) + end + + it 'returns a valid client and access token' do + token = response.header['access-token'] + client = response.header['client'] + expect(user.reload.valid_token?(token, client)).to be_truthy + end + end end