2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Auth::ManagedAuthenticator do
|
2018-11-28 23:44:16 +08:00
|
|
|
let(:authenticator) do
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
2018-12-04 11:48:13 +08:00
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
2023-01-04 15:51:10 +08:00
|
|
|
|
|
|
|
def primary_email_verified?(auth_token)
|
|
|
|
auth_token[:info][:email_verified]
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2023-01-04 15:51:10 +08:00
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
.new
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:hash) do
|
2020-02-06 00:03:18 +08:00
|
|
|
OmniAuth::AuthHash.new(
|
2018-11-28 23:44:16 +08:00
|
|
|
provider: "myauth",
|
|
|
|
uid: "1234",
|
|
|
|
info: {
|
|
|
|
name: "Best Display Name",
|
|
|
|
email: "awesome@example.com",
|
2023-01-04 15:51:10 +08:00
|
|
|
nickname: "IAmGroot",
|
|
|
|
email_verified: true,
|
2018-11-28 23:44:16 +08:00
|
|
|
},
|
|
|
|
credentials: {
|
|
|
|
token: "supersecrettoken",
|
|
|
|
},
|
|
|
|
extra: {
|
|
|
|
raw_info: {
|
|
|
|
randominfo: "some info",
|
|
|
|
},
|
|
|
|
},
|
2020-02-06 00:03:18 +08:00
|
|
|
)
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
|
2020-02-06 00:03:18 +08:00
|
|
|
let(:create_hash) { OmniAuth::AuthHash.new(provider: "myauth", uid: "1234") }
|
2018-12-10 23:10:06 +08:00
|
|
|
|
2021-12-09 20:30:27 +08:00
|
|
|
def create_auth_result(attrs)
|
|
|
|
auth_result = Auth::Result.new
|
|
|
|
attrs.each { |k, v| auth_result.send("#{k}=", v) }
|
|
|
|
auth_result
|
|
|
|
end
|
|
|
|
|
2018-11-28 23:44:16 +08:00
|
|
|
describe "after_authenticate" do
|
|
|
|
it "can match account from an existing association" do
|
|
|
|
user = Fabricate(:user)
|
2019-02-27 23:29:26 +08:00
|
|
|
associated =
|
|
|
|
UserAssociatedAccount.create!(
|
|
|
|
user: user,
|
|
|
|
provider_name: "myauth",
|
|
|
|
provider_uid: "1234",
|
|
|
|
last_used: 1.year.ago,
|
|
|
|
)
|
2018-11-28 23:44:16 +08:00
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
associated.reload
|
2019-02-27 23:29:26 +08:00
|
|
|
expect(associated.last_used).to be >= 1.day.ago
|
2018-11-28 23:44:16 +08:00
|
|
|
expect(associated.info["name"]).to eq("Best Display Name")
|
|
|
|
expect(associated.info["email"]).to eq("awesome@example.com")
|
|
|
|
expect(associated.credentials["token"]).to eq("supersecrettoken")
|
|
|
|
expect(associated.extra["raw_info"]["randominfo"]).to eq("some info")
|
|
|
|
end
|
|
|
|
|
2021-02-12 00:26:43 +08:00
|
|
|
it "only sets email valid for present strings" do
|
|
|
|
# (Twitter sometimes sends empty email strings)
|
2023-01-04 15:51:10 +08:00
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
create_hash.merge(info: { email: "email@example.com", email_verified: true }),
|
|
|
|
)
|
2021-02-12 00:26:43 +08:00
|
|
|
expect(result.email_valid).to eq(true)
|
|
|
|
|
2023-01-04 15:51:10 +08:00
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
create_hash.merge(info: { email: "", email_verified: true }),
|
|
|
|
)
|
2021-02-12 00:26:43 +08:00
|
|
|
expect(result.email_valid).to be_falsey
|
|
|
|
|
2023-01-04 15:51:10 +08:00
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
create_hash.merge(info: { email: nil, email_verified: true }),
|
|
|
|
)
|
2021-02-12 00:26:43 +08:00
|
|
|
expect(result.email_valid).to be_falsey
|
|
|
|
end
|
|
|
|
|
2023-01-04 15:51:10 +08:00
|
|
|
it "does not set email valid if email_verified is false" do
|
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
create_hash.merge(info: { email: "email@example.com", email_verified: false }),
|
|
|
|
)
|
|
|
|
expect(result.email_valid).to eq(false)
|
|
|
|
end
|
|
|
|
|
2018-11-28 23:44:16 +08:00
|
|
|
describe "connecting to another user account" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user1) { Fabricate(:user) }
|
|
|
|
fab!(:user2) { Fabricate(:user) }
|
2018-11-28 23:44:16 +08:00
|
|
|
before do
|
|
|
|
UserAssociatedAccount.create!(user: user1, provider_name: "myauth", provider_uid: "1234")
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
|
|
|
|
it "works by default" do
|
|
|
|
result = authenticator.after_authenticate(hash, existing_account: user2)
|
|
|
|
expect(result.user.id).to eq(user2.id)
|
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user1.id)).to eq(false)
|
2018-12-07 22:12:08 +08:00
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user2.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "still works if another user has a matching email" do
|
|
|
|
Fabricate(:user, email: hash.dig(:info, :email))
|
|
|
|
result = authenticator.after_authenticate(hash, existing_account: user2)
|
|
|
|
expect(result.user.id).to eq(user2.id)
|
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user1.id)).to eq(false)
|
2018-11-28 23:44:16 +08:00
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user2.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not work when disabled" do
|
|
|
|
authenticator =
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
2018-12-04 11:48:13 +08:00
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
|
|
|
def can_connect_existing_user?
|
|
|
|
false
|
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
|
|
|
.new
|
|
|
|
result = authenticator.after_authenticate(hash, existing_account: user2)
|
|
|
|
expect(result.user.id).to eq(user1.id)
|
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user1.id)).to eq(true)
|
|
|
|
expect(UserAssociatedAccount.exists?(user_id: user2.id)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "match by email" do
|
2019-08-14 00:53:38 +08:00
|
|
|
it "downcases the email address from the authprovider" do
|
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(hash.deep_merge(info: { email: "HELLO@example.com" }))
|
|
|
|
expect(result.email).to eq("hello@example.com")
|
|
|
|
end
|
|
|
|
|
2018-11-28 23:44:16 +08:00
|
|
|
it "works normally" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
result = authenticator.after_authenticate(hash.deep_merge(info: { email: user.email }))
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
expect(
|
|
|
|
UserAssociatedAccount.find_by(provider_name: "myauth", provider_uid: "1234").user_id,
|
|
|
|
).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works if there is already an association with the target account" do
|
|
|
|
user = Fabricate(:user, email: "awesome@example.com")
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not match if match_by_email is false" do
|
|
|
|
authenticator =
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
2018-12-04 11:48:13 +08:00
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
|
|
|
def match_by_email
|
|
|
|
false
|
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
|
|
|
.new
|
|
|
|
user = Fabricate(:user, email: "awesome@example.com")
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no matching user" do
|
|
|
|
it "returns the correct information" do
|
2018-12-10 23:10:06 +08:00
|
|
|
expect {
|
|
|
|
result = authenticator.after_authenticate(hash)
|
2018-12-11 17:58:20 +08:00
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
expect(result.username).to eq("IAmGroot")
|
|
|
|
expect(result.email).to eq("awesome@example.com")
|
2018-12-10 23:10:06 +08:00
|
|
|
}.to change { UserAssociatedAccount.count }.by(1)
|
|
|
|
expect(UserAssociatedAccount.last.user).to eq(nil)
|
|
|
|
expect(UserAssociatedAccount.last.info["nickname"]).to eq("IAmGroot")
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "works if there is already an association with the target account" do
|
|
|
|
user = Fabricate(:user, email: "awesome@example.com")
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
end
|
2019-08-14 19:08:59 +08:00
|
|
|
|
|
|
|
it "works if there is no email" do
|
|
|
|
expect {
|
|
|
|
result = authenticator.after_authenticate(hash.deep_merge(info: { email: nil }))
|
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
expect(result.username).to eq("IAmGroot")
|
|
|
|
expect(result.email).to eq(nil)
|
|
|
|
}.to change { UserAssociatedAccount.count }.by(1)
|
|
|
|
expect(UserAssociatedAccount.last.user).to eq(nil)
|
|
|
|
expect(UserAssociatedAccount.last.info["nickname"]).to eq("IAmGroot")
|
|
|
|
end
|
2020-02-06 00:03:18 +08:00
|
|
|
|
|
|
|
it "will ignore name when equal to email" do
|
|
|
|
result = authenticator.after_authenticate(hash.deep_merge(info: { name: hash.info.email }))
|
|
|
|
expect(result.email).to eq(hash.info.email)
|
|
|
|
expect(result.name).to eq(nil)
|
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
2018-12-04 23:09:32 +08:00
|
|
|
|
|
|
|
describe "avatar on update" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-12-04 23:09:32 +08:00
|
|
|
let!(:associated) do
|
|
|
|
UserAssociatedAccount.create!(user: user, provider_name: "myauth", provider_uid: "1234")
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-12-04 23:09:32 +08:00
|
|
|
|
|
|
|
it "schedules the job upon update correctly" do
|
|
|
|
# No image supplied, do not schedule
|
|
|
|
expect { result = authenticator.after_authenticate(hash) }.not_to change {
|
2022-07-19 22:03:03 +08:00
|
|
|
Jobs::DownloadAvatarFromUrl.jobs.count
|
|
|
|
}
|
2018-12-04 23:09:32 +08:00
|
|
|
|
|
|
|
# Image supplied, schedule
|
|
|
|
expect {
|
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
hash.deep_merge(info: { image: "https://some.domain/image.jpg" }),
|
|
|
|
)
|
|
|
|
}.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(1)
|
|
|
|
|
|
|
|
# User already has profile picture, don't schedule
|
|
|
|
user.user_avatar = Fabricate(:user_avatar, custom_upload: Fabricate(:upload))
|
|
|
|
user.save!
|
|
|
|
expect {
|
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
hash.deep_merge(info: { image: "https://some.domain/image.jpg" }),
|
|
|
|
)
|
2022-07-19 22:03:03 +08:00
|
|
|
}.not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }
|
2018-12-04 23:09:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-07 22:04:21 +08:00
|
|
|
describe "profile on update" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-12-07 22:04:21 +08:00
|
|
|
let!(:associated) do
|
|
|
|
UserAssociatedAccount.create!(user: user, provider_name: "myauth", provider_uid: "1234")
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-12-07 22:04:21 +08:00
|
|
|
|
|
|
|
it "updates the user's location and bio, unless already set" do
|
|
|
|
{ description: :bio_raw, location: :location }.each do |auth_hash_key, profile_key|
|
|
|
|
user.user_profile.update(profile_key => "Initial Value")
|
|
|
|
# No value supplied, do not overwrite
|
|
|
|
expect { result = authenticator.after_authenticate(hash) }.not_to change {
|
|
|
|
user.user_profile.reload
|
|
|
|
user.user_profile[profile_key]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Value supplied, still do not overwrite
|
|
|
|
expect {
|
|
|
|
result =
|
|
|
|
authenticator.after_authenticate(
|
|
|
|
hash.deep_merge(info: { auth_hash_key => "New Value" }),
|
|
|
|
)
|
|
|
|
}.not_to change {
|
|
|
|
user.user_profile.reload
|
|
|
|
user.user_profile[profile_key]
|
|
|
|
}
|
|
|
|
|
|
|
|
# User has not set a value, so overwrite
|
|
|
|
user.user_profile.update(profile_key => "")
|
|
|
|
authenticator.after_authenticate(hash.deep_merge(info: { auth_hash_key => "New Value" }))
|
|
|
|
user.user_profile.reload
|
|
|
|
expect(user.user_profile[profile_key]).to eq("New Value")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-04 23:09:32 +08:00
|
|
|
describe "avatar on create" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-12-10 23:10:06 +08:00
|
|
|
let!(:association) do
|
|
|
|
UserAssociatedAccount.create!(provider_name: "myauth", provider_uid: "1234")
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-12-10 23:10:06 +08:00
|
|
|
|
2018-12-04 23:09:32 +08:00
|
|
|
it "doesn't schedule with no image" do
|
2021-12-09 20:30:27 +08:00
|
|
|
expect {
|
|
|
|
result =
|
|
|
|
authenticator.after_create_account(user, create_auth_result(extra_data: create_hash))
|
2022-07-19 22:03:03 +08:00
|
|
|
}.not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }
|
2018-12-04 23:09:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "schedules with image" do
|
2018-12-10 23:10:06 +08:00
|
|
|
association.info["image"] = "https://some.domain/image.jpg"
|
|
|
|
association.save!
|
2021-12-09 20:30:27 +08:00
|
|
|
expect {
|
|
|
|
result =
|
|
|
|
authenticator.after_create_account(user, create_auth_result(extra_data: create_hash))
|
2018-12-04 23:09:32 +08:00
|
|
|
}.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
2018-12-07 22:04:21 +08:00
|
|
|
|
|
|
|
describe "profile on create" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-12-10 23:10:06 +08:00
|
|
|
let!(:association) do
|
|
|
|
UserAssociatedAccount.create!(provider_name: "myauth", provider_uid: "1234")
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2018-12-10 23:10:06 +08:00
|
|
|
|
2018-12-07 22:04:21 +08:00
|
|
|
it "doesn't explode without profile" do
|
2021-12-09 20:30:27 +08:00
|
|
|
authenticator.after_create_account(user, create_auth_result(extra_data: create_hash))
|
2018-12-07 22:04:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "works with profile" do
|
2018-12-10 23:10:06 +08:00
|
|
|
association.info["location"] = "DiscourseVille"
|
|
|
|
association.info["description"] = "Online forum expert"
|
|
|
|
association.save!
|
2021-12-09 20:30:27 +08:00
|
|
|
authenticator.after_create_account(user, create_auth_result(extra_data: create_hash))
|
2018-12-07 22:04:21 +08:00
|
|
|
expect(user.user_profile.bio_raw).to eq("Online forum expert")
|
|
|
|
expect(user.user_profile.location).to eq("DiscourseVille")
|
|
|
|
end
|
|
|
|
end
|
2022-10-11 18:25:13 +08:00
|
|
|
|
|
|
|
describe "match by username" do
|
|
|
|
let(:user_match_authenticator) do
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
|
|
|
def match_by_email
|
|
|
|
false
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2022-10-11 18:25:13 +08:00
|
|
|
def match_by_username
|
2023-01-09 19:18:21 +08:00
|
|
|
true
|
|
|
|
end
|
2022-10-11 18:25:13 +08:00
|
|
|
end
|
|
|
|
.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works normally" do
|
|
|
|
SiteSetting.username_change_period = 0
|
|
|
|
user = Fabricate(:user)
|
|
|
|
result =
|
|
|
|
user_match_authenticator.after_authenticate(
|
|
|
|
hash.deep_merge(info: { nickname: user.username }),
|
|
|
|
)
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
expect(
|
|
|
|
UserAssociatedAccount.find_by(provider_name: "myauth", provider_uid: "1234").user_id,
|
|
|
|
).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works if there is already an association with the target account" do
|
|
|
|
SiteSetting.username_change_period = 0
|
|
|
|
user = Fabricate(:user, username: "IAmGroot")
|
|
|
|
result = user_match_authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works if the username is different case" do
|
|
|
|
SiteSetting.username_change_period = 0
|
|
|
|
user = Fabricate(:user, username: "IAMGROOT")
|
|
|
|
result = user_match_authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user.id).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not match if username_change_period isn\'t 0' do
|
|
|
|
SiteSetting.username_change_period = 3
|
|
|
|
user = Fabricate(:user, username: "IAmGroot")
|
|
|
|
result = user_match_authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not match if default match_by_username not overriden" do
|
|
|
|
SiteSetting.username_change_period = 0
|
|
|
|
authenticator =
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
.new
|
|
|
|
user = Fabricate(:user, username: "IAmGroot")
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not match if match_by_username is false" do
|
|
|
|
SiteSetting.username_change_period = 0
|
|
|
|
authenticator =
|
|
|
|
Class
|
|
|
|
.new(described_class) do
|
|
|
|
def name
|
|
|
|
"myauth"
|
|
|
|
end
|
|
|
|
def match_by_username
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
.new
|
|
|
|
user = Fabricate(:user, username: "IAmGroot")
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "description_for_user" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-11-28 23:44:16 +08:00
|
|
|
|
|
|
|
it "returns empty string if no entry for user" do
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns correct information" do
|
|
|
|
association =
|
|
|
|
UserAssociatedAccount.create!(
|
|
|
|
user: user,
|
|
|
|
provider_name: "myauth",
|
|
|
|
provider_uid: "1234",
|
|
|
|
info: {
|
|
|
|
nickname: "somenickname",
|
|
|
|
email: "test@domain.tld",
|
|
|
|
name: "bestname",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("test@domain.tld")
|
|
|
|
association.update(info: { nickname: "somenickname", name: "bestname" })
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("somenickname")
|
|
|
|
association.update(info: { nickname: "bestname" })
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("bestname")
|
2019-06-03 19:14:02 +08:00
|
|
|
association.update(info: {})
|
|
|
|
expect(authenticator.description_for_user(user)).to eq(
|
|
|
|
I18n.t("associated_accounts.connected"),
|
|
|
|
)
|
2018-11-28 23:44:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "revoke" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-11-28 23:44:16 +08:00
|
|
|
|
|
|
|
it "raises exception if no entry for user" do
|
|
|
|
expect { authenticator.revoke(user) }.to raise_error(Discourse::NotFound)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid record" do
|
|
|
|
before do
|
|
|
|
UserAssociatedAccount.create!(
|
|
|
|
user: user,
|
|
|
|
provider_name: "myauth",
|
|
|
|
provider_uid: "1234",
|
|
|
|
info: {
|
|
|
|
name: "somename",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "revokes correctly" do
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("somename")
|
|
|
|
expect(authenticator.can_revoke?).to eq(true)
|
|
|
|
expect(authenticator.revoke(user)).to eq(true)
|
|
|
|
|
|
|
|
expect(authenticator.description_for_user(user)).to eq("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|