2015-10-11 05:41:23 -04:00
|
|
|
require "rails_helper"
|
2015-03-06 16:44:54 -05:00
|
|
|
|
|
|
|
describe UserAnonymizer do
|
|
|
|
|
|
|
|
describe "make_anonymous" do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
2017-01-31 17:21:37 -05:00
|
|
|
let(:user) { Fabricate(:user, username: "edward") }
|
2015-03-06 16:44:54 -05:00
|
|
|
|
|
|
|
subject(:make_anonymous) { described_class.make_anonymous(user, admin) }
|
|
|
|
|
|
|
|
it "changes username" do
|
|
|
|
make_anonymous
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.reload.username).to match(/^anon\d{3,}$/)
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "changes email address" do
|
|
|
|
make_anonymous
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.reload.email).to eq("#{user.username}@example.com")
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "turns off all notifications" do
|
2016-02-16 23:46:19 -05:00
|
|
|
user.user_option.update_columns(
|
|
|
|
email_always: true
|
|
|
|
)
|
|
|
|
|
2015-03-06 16:44:54 -05:00
|
|
|
make_anonymous
|
|
|
|
user.reload
|
2016-02-16 23:46:19 -05:00
|
|
|
expect(user.user_option.email_digests).to eq(false)
|
|
|
|
expect(user.user_option.email_private_messages).to eq(false)
|
|
|
|
expect(user.user_option.email_direct).to eq(false)
|
|
|
|
expect(user.user_option.email_always).to eq(false)
|
|
|
|
expect(user.user_option.mailing_list_mode).to eq(false)
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
2016-03-17 18:43:48 -04:00
|
|
|
context "Site Settings do not require full name" do
|
|
|
|
before do
|
|
|
|
SiteSetting.full_name_required = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resets profile to default values" do
|
2017-07-27 21:20:09 -04:00
|
|
|
user.update_attributes(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
2016-03-17 18:43:48 -04:00
|
|
|
|
|
|
|
profile = user.user_profile(true)
|
2017-07-27 21:20:09 -04:00
|
|
|
profile.update_attributes(location: "Moose Jaw",
|
|
|
|
website: "www.bim.com",
|
|
|
|
bio_raw: "I'm Bibi from Moosejaw. I sing and dance.",
|
|
|
|
bio_cooked: "I'm Bibi from Moosejaw. I sing and dance.",
|
|
|
|
profile_background: "http://example.com/bg.jpg",
|
|
|
|
bio_cooked_version: 2,
|
|
|
|
card_background: "http://example.com/cb.jpg")
|
2016-03-17 21:32:09 -04:00
|
|
|
|
|
|
|
prev_username = user.username
|
|
|
|
|
2017-01-31 17:21:37 -05:00
|
|
|
UserAuthToken.generate!(user_id: user.id)
|
|
|
|
|
2016-03-17 18:43:48 -04:00
|
|
|
make_anonymous
|
|
|
|
user.reload
|
|
|
|
|
2016-03-17 21:32:09 -04:00
|
|
|
expect(user.username).not_to eq(prev_username)
|
2016-03-17 18:43:48 -04:00
|
|
|
expect(user.name).not_to be_present
|
|
|
|
expect(user.date_of_birth).to eq(nil)
|
|
|
|
expect(user.title).not_to be_present
|
2017-01-31 17:21:37 -05:00
|
|
|
expect(user.user_auth_tokens.count).to eq(0)
|
2016-03-17 18:43:48 -04:00
|
|
|
|
|
|
|
profile = user.user_profile(true)
|
|
|
|
expect(profile.location).to eq(nil)
|
|
|
|
expect(profile.website).to eq(nil)
|
|
|
|
expect(profile.bio_cooked).to eq(nil)
|
|
|
|
expect(profile.profile_background).to eq(nil)
|
|
|
|
expect(profile.bio_cooked_version).to eq(nil)
|
|
|
|
expect(profile.card_background).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "Site Settings require full name" do
|
|
|
|
before do
|
|
|
|
SiteSetting.full_name_required = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "changes name to anonymized username" do
|
2016-03-17 21:32:09 -04:00
|
|
|
prev_username = user.username
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
user.update_attributes(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
2016-03-17 18:43:48 -04:00
|
|
|
|
|
|
|
make_anonymous
|
|
|
|
user.reload
|
2015-03-06 16:44:54 -05:00
|
|
|
|
2016-03-17 21:32:09 -04:00
|
|
|
expect(user.name).not_to eq(prev_username)
|
2016-03-17 18:43:48 -04:00
|
|
|
expect(user.name).to eq(user.username)
|
|
|
|
end
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "removes the avatar" do
|
|
|
|
upload = Fabricate(:upload, user: user)
|
|
|
|
user.user_avatar = UserAvatar.new(user_id: user.id, custom_upload_id: upload.id)
|
2015-11-27 14:37:20 -05:00
|
|
|
user.uploaded_avatar_id = upload.id # chosen in user preferences
|
2015-03-06 16:44:54 -05:00
|
|
|
user.save!
|
|
|
|
expect { make_anonymous }.to change { Upload.count }.by(-1)
|
|
|
|
user.reload
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.user_avatar).to eq(nil)
|
2015-11-27 14:37:20 -05:00
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "logs the action" do
|
|
|
|
expect { make_anonymous }.to change { UserHistory.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes external auth assocations" do
|
|
|
|
user.twitter_user_info = TwitterUserInfo.create(user_id: user.id, screen_name: "example", twitter_user_id: "examplel123123")
|
|
|
|
user.google_user_info = GoogleUserInfo.create(user_id: user.id, google_user_id: "google@gmail.com")
|
|
|
|
user.github_user_info = GithubUserInfo.create(user_id: user.id, screen_name: "example", github_user_id: "examplel123123")
|
|
|
|
user.facebook_user_info = FacebookUserInfo.create(user_id: user.id, facebook_user_id: "example")
|
|
|
|
user.single_sign_on_record = SingleSignOnRecord.create(user_id: user.id, external_id: "example", last_payload: "looks good")
|
|
|
|
user.oauth2_user_info = Oauth2UserInfo.create(user_id: user.id, uid: "example", provider: "example")
|
|
|
|
UserOpenId.create(user_id: user.id, email: user.email, url: "http://example.com/openid", active: true)
|
|
|
|
make_anonymous
|
|
|
|
user.reload
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.twitter_user_info).to eq(nil)
|
|
|
|
expect(user.google_user_info).to eq(nil)
|
|
|
|
expect(user.github_user_info).to eq(nil)
|
|
|
|
expect(user.facebook_user_info).to eq(nil)
|
|
|
|
expect(user.single_sign_on_record).to eq(nil)
|
|
|
|
expect(user.oauth2_user_info).to eq(nil)
|
|
|
|
expect(user.user_open_ids.count).to eq(0)
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "removes api key" do
|
|
|
|
ApiKey.create(user_id: user.id, key: "123123123")
|
|
|
|
expect { make_anonymous }.to change { ApiKey.count }.by(-1)
|
|
|
|
user.reload
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.api_key).to eq(nil)
|
2015-03-06 16:44:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|