Defect #44343 ยป user-destroy-oauth-grants-tokens.patch
| app/models/user.rb | ||
|---|---|---|
| 104 | 104 |
has_many :email_addresses, :dependent => :delete_all |
| 105 | 105 |
has_many :reactions, dependent: :delete_all |
| 106 | 106 |
has_many :webhooks, dependent: :destroy |
| 107 |
has_many :oauth_access_grants, :class_name => 'Doorkeeper::AccessGrant', |
|
| 108 |
:foreign_key => :resource_owner_id, :dependent => :delete_all |
|
| 109 |
has_many :oauth_access_tokens, :class_name => 'Doorkeeper::AccessToken', |
|
| 110 |
:foreign_key => :resource_owner_id, :dependent => :delete_all |
|
| 107 | 111 | |
| 108 | 112 |
belongs_to :auth_source |
| 109 | 113 | |
| test/unit/user_test.rb | ||
|---|---|---|
| 400 | 400 |
assert_nil Token.find_by_id(token.id) |
| 401 | 401 |
end |
| 402 | 402 | |
| 403 |
def test_destroy_should_delete_oauth_access_grants |
|
| 404 |
application = Doorkeeper::Application.create!( |
|
| 405 |
:name => 'Test App', |
|
| 406 |
:redirect_uri => 'http://localhost/callback', |
|
| 407 |
:scopes => 'view_issues' |
|
| 408 |
) |
|
| 409 |
grant = Doorkeeper::AccessGrant.create!( |
|
| 410 |
:application_id => application.id, |
|
| 411 |
:resource_owner_id => 2, |
|
| 412 |
:redirect_uri => application.redirect_uri, |
|
| 413 |
:scopes => 'view_issues', |
|
| 414 |
:expires_in => 600 |
|
| 415 |
) |
|
| 416 | ||
| 417 |
User.find(2).destroy |
|
| 418 |
assert_nil User.find_by_id(2) |
|
| 419 |
assert_nil Doorkeeper::AccessGrant.find_by_id(grant.id) |
|
| 420 |
end |
|
| 421 | ||
| 422 |
def test_destroy_should_delete_oauth_access_tokens |
|
| 423 |
application = Doorkeeper::Application.create!( |
|
| 424 |
:name => 'Test App', |
|
| 425 |
:redirect_uri => 'http://localhost/callback', |
|
| 426 |
:scopes => 'view_issues' |
|
| 427 |
) |
|
| 428 |
token = Doorkeeper::AccessToken.create!( |
|
| 429 |
:application_id => application.id, |
|
| 430 |
:resource_owner_id => 2, |
|
| 431 |
:scopes => 'view_issues', |
|
| 432 |
:expires_in => 7200 |
|
| 433 |
) |
|
| 434 | ||
| 435 |
User.find(2).destroy |
|
| 436 |
assert_nil User.find_by_id(2) |
|
| 437 |
assert_nil Doorkeeper::AccessToken.find_by_id(token.id) |
|
| 438 |
end |
|
| 439 | ||
| 403 | 440 |
def test_destroy_should_delete_watchers |
| 404 | 441 |
issue = Issue.create!(:project_id => 1, :author_id => 1, |
| 405 | 442 |
:tracker_id => 1, :subject => 'foo') |