graphql_devise 0.18.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +7 -2
- data/.gitignore +3 -0
- data/.rubocop.yml +9 -10
- data/Appraisals +70 -18
- data/CHANGELOG.md +53 -0
- data/README.md +71 -142
- data/app/controllers/graphql_devise/graphql_controller.rb +3 -3
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -5
- data/config/routes.rb +0 -2
- data/graphql_devise.gemspec +7 -5
- data/lib/graphql_devise/concerns/additional_controller_methods.rb +48 -0
- data/lib/graphql_devise/concerns/additional_model_methods.rb +17 -0
- data/lib/graphql_devise/concerns/authenticatable.rb +1 -1
- data/lib/graphql_devise/concerns/controller_methods.rb +70 -93
- data/lib/graphql_devise/concerns/field_authentication.rb +14 -0
- data/lib/graphql_devise/concerns/set_user_by_token.rb +1 -1
- data/lib/graphql_devise/default_operations.rb +16 -0
- data/lib/graphql_devise/engine.rb +0 -2
- data/lib/graphql_devise/model/with_email_updater.rb +5 -30
- data/lib/graphql_devise/mount_method/operation_preparer.rb +0 -7
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +0 -12
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +0 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +1 -1
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +1 -1
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +0 -2
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +1 -1
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +1 -1
- data/lib/graphql_devise/mount_method/options_validator.rb +0 -3
- data/lib/graphql_devise/mount_method/supported_options.rb +0 -5
- data/lib/graphql_devise/mutations/base.rb +1 -1
- data/lib/graphql_devise/mutations/confirm_registration_with_token.rb +1 -1
- data/lib/graphql_devise/mutations/login.rb +1 -1
- data/lib/graphql_devise/mutations/register.rb +1 -1
- data/lib/graphql_devise/mutations/update_password_with_token.rb +1 -1
- data/lib/graphql_devise/resolvers/base.rb +1 -1
- data/lib/graphql_devise/resource_loader.rb +71 -39
- data/lib/graphql_devise/route_mounter.rb +13 -0
- data/lib/graphql_devise/schema_plugin.rb +7 -40
- data/lib/graphql_devise/types/authenticatable_type.rb +1 -1
- data/lib/graphql_devise/types/base_field.rb +9 -0
- data/lib/graphql_devise/types/base_type.rb +8 -0
- data/lib/graphql_devise/types/credential_type.rb +1 -1
- data/lib/graphql_devise/types/mutation_type.rb +1 -0
- data/lib/graphql_devise/types/query_type.rb +1 -0
- data/lib/graphql_devise/version.rb +1 -1
- data/lib/graphql_devise.rb +21 -29
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +1 -16
- data/spec/dummy/app/graphql/dummy_schema.rb +1 -5
- data/spec/dummy/app/graphql/interpreter_schema.rb +6 -2
- data/spec/dummy/app/graphql/mutations/base_mutation.rb +6 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +2 -4
- data/spec/dummy/app/graphql/types/admin_type.rb +1 -1
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +1 -1
- data/spec/dummy/app/graphql/types/mutation_type.rb +3 -1
- data/spec/dummy/app/graphql/types/query_type.rb +3 -1
- data/spec/dummy/app/graphql/types/user_type.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/routes.rb +5 -9
- data/spec/graphql_devise/model/with_email_updater_spec.rb +17 -35
- data/spec/rails_helper.rb +5 -5
- data/spec/requests/mutations/resend_confirmation_with_token_spec.rb +2 -3
- data/spec/requests/user_controller_spec.rb +1 -33
- data/spec/services/resource_loader_spec.rb +14 -3
- metadata +55 -48
- data/app/controllers/graphql_devise/concerns/additional_controller_methods.rb +0 -72
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +0 -21
- data/app/helpers/graphql_devise/mailer_helper.rb +0 -37
- data/app/models/graphql_devise/concerns/additional_model_methods.rb +0 -21
- data/app/models/graphql_devise/concerns/model.rb +0 -25
- data/lib/graphql_devise/default_operations/mutations.rb +0 -32
- data/lib/graphql_devise/default_operations/resolvers.rb +0 -14
- data/lib/graphql_devise/mutations/resend_confirmation.rb +0 -45
- data/lib/graphql_devise/mutations/send_password_reset.rb +0 -38
- data/lib/graphql_devise/mutations/sign_up.rb +0 -61
- data/lib/graphql_devise/mutations/update_password.rb +0 -46
- data/lib/graphql_devise/rails/routes.rb +0 -15
- data/lib/graphql_devise/resolvers/check_password_token.rb +0 -43
- data/lib/graphql_devise/resolvers/confirm_account.rb +0 -42
- data/spec/dummy/app/graphql/mutations/sign_up.rb +0 -14
- data/spec/dummy/app/graphql/resolvers/confirm_admin_account.rb +0 -13
- data/spec/requests/mutations/resend_confirmation_spec.rb +0 -153
- data/spec/requests/mutations/send_password_reset_spec.rb +0 -103
- data/spec/requests/mutations/sign_up_spec.rb +0 -170
- data/spec/requests/mutations/update_password_spec.rb +0 -116
- data/spec/requests/queries/check_password_token_spec.rb +0 -149
- data/spec/requests/queries/confirm_account_spec.rb +0 -137
@@ -1,149 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'Check Password Token Requests' do
|
6
|
-
include_context 'with graphql query request'
|
7
|
-
|
8
|
-
let(:user) { create(:user, :confirmed) }
|
9
|
-
let(:redirect_url) { 'https://google.com' }
|
10
|
-
|
11
|
-
context 'when using the user model' do
|
12
|
-
let(:query) do
|
13
|
-
<<-GRAPHQL
|
14
|
-
query {
|
15
|
-
userCheckPasswordToken(
|
16
|
-
resetPasswordToken: "#{token}",
|
17
|
-
redirectUrl: "#{redirect_url}"
|
18
|
-
) {
|
19
|
-
email
|
20
|
-
}
|
21
|
-
}
|
22
|
-
GRAPHQL
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when reset password token is valid' do
|
26
|
-
let(:token) { user.send(:set_reset_password_token) }
|
27
|
-
|
28
|
-
context 'when redirect_url is not provided' do
|
29
|
-
let(:redirect_url) { nil }
|
30
|
-
|
31
|
-
it 'returns authenticatable and credentials in the headers' do
|
32
|
-
get_request
|
33
|
-
|
34
|
-
expect(response).to include_auth_headers
|
35
|
-
expect(json_response[:data][:userCheckPasswordToken]).to match(
|
36
|
-
email: user.email
|
37
|
-
)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when redirect url is provided' do
|
42
|
-
it 'redirects to redirect url' do
|
43
|
-
expect do
|
44
|
-
get_request
|
45
|
-
|
46
|
-
user.reload
|
47
|
-
end.to change { user.tokens.keys.count }.from(0).to(1).and(
|
48
|
-
change(user, :allow_password_change).from(false).to(true)
|
49
|
-
)
|
50
|
-
|
51
|
-
expect(response).to redirect_to %r{\Ahttps://google.com}
|
52
|
-
expect(response.body).to include("client=#{user.reload.tokens.keys.first}")
|
53
|
-
expect(response.body).to include('access-token=')
|
54
|
-
expect(response.body).to include('uid=')
|
55
|
-
expect(response.body).to include('expiry=')
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when redirect_url is not whitelisted' do
|
59
|
-
let(:redirect_url) { 'https://not-safe.com' }
|
60
|
-
|
61
|
-
before { post_request }
|
62
|
-
|
63
|
-
it 'returns a not whitelisted redirect url error' do
|
64
|
-
expect(json_response[:errors]).to containing_exactly(
|
65
|
-
hash_including(
|
66
|
-
message: "Redirect to '#{redirect_url}' not allowed.",
|
67
|
-
extensions: { code: 'USER_ERROR' }
|
68
|
-
)
|
69
|
-
)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when token has expired' do
|
75
|
-
it 'returns an expired token error' do
|
76
|
-
travel_to 10.hours.ago do
|
77
|
-
token
|
78
|
-
end
|
79
|
-
|
80
|
-
get_request
|
81
|
-
|
82
|
-
expect(json_response[:errors]).to contain_exactly(
|
83
|
-
hash_including(message: 'Reset password token is no longer valid.', extensions: { code: 'USER_ERROR' })
|
84
|
-
)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when reset password token is not found' do
|
90
|
-
let(:token) { user.send(:set_reset_password_token) + 'invalid' }
|
91
|
-
|
92
|
-
it 'returns an error message' do
|
93
|
-
get_request
|
94
|
-
|
95
|
-
expect(json_response[:errors]).to contain_exactly(
|
96
|
-
hash_including(message: 'No user found for the specified reset token.', extensions: { code: 'USER_ERROR' })
|
97
|
-
)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'when using the admin model' do
|
103
|
-
let(:token) { 'not_important' }
|
104
|
-
let(:query) do
|
105
|
-
<<-GRAPHQL
|
106
|
-
query {
|
107
|
-
adminCheckPasswordToken(
|
108
|
-
resetPasswordToken: "#{token}",
|
109
|
-
redirectUrl: "#{redirect_url}"
|
110
|
-
) {
|
111
|
-
email
|
112
|
-
}
|
113
|
-
}
|
114
|
-
GRAPHQL
|
115
|
-
end
|
116
|
-
|
117
|
-
before { post_request }
|
118
|
-
|
119
|
-
it 'skips the sign up mutation' do
|
120
|
-
expect(json_response[:errors]).to contain_exactly(
|
121
|
-
hash_including(message: "Field 'adminCheckPasswordToken' doesn't exist on type 'Query'")
|
122
|
-
)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when using the guest model' do
|
127
|
-
let(:token) { 'not_important' }
|
128
|
-
let(:query) do
|
129
|
-
<<-GRAPHQL
|
130
|
-
query {
|
131
|
-
guestCheckPasswordToken(
|
132
|
-
resetPasswordToken: "#{token}",
|
133
|
-
redirectUrl: "#{redirect_url}"
|
134
|
-
) {
|
135
|
-
email
|
136
|
-
}
|
137
|
-
}
|
138
|
-
GRAPHQL
|
139
|
-
end
|
140
|
-
|
141
|
-
before { post_request }
|
142
|
-
|
143
|
-
it 'skips the sign up mutation' do
|
144
|
-
expect(json_response[:errors]).to contain_exactly(
|
145
|
-
hash_including(message: "Field 'guestCheckPasswordToken' doesn't exist on type 'Query'")
|
146
|
-
)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'Account confirmation' do
|
6
|
-
include_context 'with graphql query request'
|
7
|
-
|
8
|
-
context 'when using the user model' do
|
9
|
-
let(:user) { create(:user, confirmed_at: nil) }
|
10
|
-
let(:redirect) { 'https://google.com' }
|
11
|
-
let(:query) do
|
12
|
-
<<-GRAPHQL
|
13
|
-
{
|
14
|
-
userConfirmAccount(
|
15
|
-
confirmationToken: "#{token}"
|
16
|
-
redirectUrl: "#{redirect}"
|
17
|
-
) {
|
18
|
-
email
|
19
|
-
name
|
20
|
-
}
|
21
|
-
}
|
22
|
-
GRAPHQL
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when confirmation token is correct' do
|
26
|
-
let(:token) { user.confirmation_token }
|
27
|
-
|
28
|
-
before do
|
29
|
-
user.send_confirmation_instructions(
|
30
|
-
template_path: ['graphql_devise/mailer'],
|
31
|
-
controller: 'graphql_devise/graphql',
|
32
|
-
schema_url: 'http://not-using-this-value.com/gql'
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'confirms the resource and redirects to the sent url' do
|
37
|
-
expect do
|
38
|
-
get_request
|
39
|
-
user.reload
|
40
|
-
end.to(change(user, :confirmed_at).from(nil))
|
41
|
-
|
42
|
-
expect(response).to redirect_to("#{redirect}?account_confirmation_success=true")
|
43
|
-
expect(user).to be_active_for_authentication
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when redirect_url is not whitelisted' do
|
47
|
-
let(:redirect) { 'https://not-safe.com' }
|
48
|
-
|
49
|
-
it 'returns a not whitelisted redirect url error' do
|
50
|
-
expect { post_request }.to not_change(ActionMailer::Base.deliveries, :count)
|
51
|
-
|
52
|
-
expect(json_response[:errors]).to containing_exactly(
|
53
|
-
hash_including(
|
54
|
-
message: "Redirect to '#{redirect}' not allowed.",
|
55
|
-
extensions: { code: 'USER_ERROR' }
|
56
|
-
)
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when unconfirmed_email is present' do
|
62
|
-
let(:user) { create(:user, :confirmed, unconfirmed_email: 'vvega@wallaceinc.com') }
|
63
|
-
|
64
|
-
it 'confirms the unconfirmed email and redirects' do
|
65
|
-
expect do
|
66
|
-
get_request
|
67
|
-
user.reload
|
68
|
-
end.to change(user, :email).from(user.email).to('vvega@wallaceinc.com').and(
|
69
|
-
change(user, :unconfirmed_email).from('vvega@wallaceinc.com').to(nil)
|
70
|
-
)
|
71
|
-
|
72
|
-
expect(response).to redirect_to("#{redirect}?account_confirmation_success=true")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when reset password token is not found' do
|
78
|
-
let(:token) { "#{user.confirmation_token}-invalid" }
|
79
|
-
|
80
|
-
it 'does *NOT* confirm the user nor does the redirection' do
|
81
|
-
expect do
|
82
|
-
get_request
|
83
|
-
user.reload
|
84
|
-
end.not_to(change(user, :confirmed_at).from(nil))
|
85
|
-
|
86
|
-
expect(response).not_to be_redirect
|
87
|
-
expect(json_response[:errors]).to contain_exactly(
|
88
|
-
hash_including(
|
89
|
-
message: 'Invalid confirmation token. Please try again',
|
90
|
-
extensions: { code: 'USER_ERROR' }
|
91
|
-
)
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when using the admin model' do
|
98
|
-
let(:admin) { create(:admin, confirmed_at: nil) }
|
99
|
-
let(:redirect) { 'https://google.com' }
|
100
|
-
let(:query) do
|
101
|
-
<<-GRAPHQL
|
102
|
-
{
|
103
|
-
adminConfirmAccount(
|
104
|
-
confirmationToken: "#{token}"
|
105
|
-
redirectUrl: "#{redirect}"
|
106
|
-
) {
|
107
|
-
email
|
108
|
-
}
|
109
|
-
}
|
110
|
-
GRAPHQL
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when confirmation token is correct' do
|
114
|
-
let(:token) { admin.confirmation_token }
|
115
|
-
|
116
|
-
before do
|
117
|
-
admin.send_confirmation_instructions(
|
118
|
-
template_path: ['graphql_devise/mailer'],
|
119
|
-
controller: 'graphql_devise/graphql',
|
120
|
-
schema_url: 'http://not-using-this-value.com/gql'
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'confirms the resource, persists credentials on the DB and redirects to the sent url' do
|
125
|
-
expect do
|
126
|
-
get_request
|
127
|
-
admin.reload
|
128
|
-
end.to change(admin, :confirmed_at).from(nil).and(
|
129
|
-
change { admin.tokens.keys.count }.from(0).to(1)
|
130
|
-
)
|
131
|
-
|
132
|
-
expect(response).to redirect_to(/\A#{redirect}.+access\-token=/)
|
133
|
-
expect(admin).to be_active_for_authentication
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|