mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe 'GitHub Oauth2' do
|
||||
describe "GitHub Oauth2" do
|
||||
let(:access_token) { "github_access_token_448" }
|
||||
let(:client_id) { "abcdef11223344" }
|
||||
let(:client_secret) { "adddcccdddd99922" }
|
||||
@ -10,19 +10,17 @@ describe 'GitHub Oauth2' do
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
|
||||
def setup_github_emails_stub(emails)
|
||||
stub_request(:get, "https://api.github.com/user/emails")
|
||||
.with(
|
||||
headers: {
|
||||
"Authorization" => "Bearer #{access_token}"
|
||||
}
|
||||
)
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: JSON.dump(emails),
|
||||
headers: {
|
||||
"Content-Type" => "application/json"
|
||||
}
|
||||
)
|
||||
stub_request(:get, "https://api.github.com/user/emails").with(
|
||||
headers: {
|
||||
"Authorization" => "Bearer #{access_token}",
|
||||
},
|
||||
).to_return(
|
||||
status: 200,
|
||||
body: JSON.dump(emails),
|
||||
headers: {
|
||||
"Content-Type" => "application/json",
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
@ -30,35 +28,34 @@ describe 'GitHub Oauth2' do
|
||||
SiteSetting.github_client_id = client_id
|
||||
SiteSetting.github_client_secret = client_secret
|
||||
|
||||
stub_request(:post, "https://github.com/login/oauth/access_token")
|
||||
.with(
|
||||
body: hash_including(
|
||||
stub_request(:post, "https://github.com/login/oauth/access_token").with(
|
||||
body:
|
||||
hash_including(
|
||||
"client_id" => client_id,
|
||||
"client_secret" => client_secret,
|
||||
"code" => temp_code,
|
||||
)
|
||||
)
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: Rack::Utils.build_query(
|
||||
),
|
||||
).to_return(
|
||||
status: 200,
|
||||
body:
|
||||
Rack::Utils.build_query(
|
||||
access_token: access_token,
|
||||
scope: "user:email",
|
||||
token_type: "bearer"
|
||||
token_type: "bearer",
|
||||
),
|
||||
headers: {
|
||||
"Content-Type" => "application/x-www-form-urlencoded"
|
||||
}
|
||||
)
|
||||
headers: {
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
},
|
||||
)
|
||||
|
||||
stub_request(:get, "https://api.github.com/user")
|
||||
.with(
|
||||
headers: {
|
||||
"Authorization" => "Bearer #{access_token}"
|
||||
}
|
||||
)
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: JSON.dump(
|
||||
stub_request(:get, "https://api.github.com/user").with(
|
||||
headers: {
|
||||
"Authorization" => "Bearer #{access_token}",
|
||||
},
|
||||
).to_return(
|
||||
status: 200,
|
||||
body:
|
||||
JSON.dump(
|
||||
login: "octocat",
|
||||
id: 1,
|
||||
node_id: "MDQ6VXNlcjE=",
|
||||
@ -94,20 +91,20 @@ describe 'GitHub Oauth2' do
|
||||
private_gists: 81,
|
||||
total_private_repos: 100,
|
||||
owned_private_repos: 100,
|
||||
disk_usage: 10000,
|
||||
disk_usage: 10_000,
|
||||
collaborators: 8,
|
||||
two_factor_authentication: true,
|
||||
plan: {
|
||||
name: "Medium",
|
||||
space: 400,
|
||||
private_repos: 20,
|
||||
collaborators: 0
|
||||
}
|
||||
collaborators: 0,
|
||||
},
|
||||
),
|
||||
headers: {
|
||||
"Content-Type" => "application/json"
|
||||
}
|
||||
)
|
||||
headers: {
|
||||
"Content-Type" => "application/json",
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
it "doesn't sign in anyone if none of the emails from github are verified" do
|
||||
@ -117,25 +114,12 @@ describe 'GitHub Oauth2' do
|
||||
|
||||
setup_github_emails_stub(
|
||||
[
|
||||
{
|
||||
email: user1.email,
|
||||
primary: true,
|
||||
verified: false,
|
||||
visibility: "private"
|
||||
},
|
||||
{
|
||||
email: user2.email,
|
||||
primary: false,
|
||||
verified: false,
|
||||
visibility: "private"
|
||||
}
|
||||
]
|
||||
{ email: user1.email, primary: true, verified: false, visibility: "private" },
|
||||
{ email: user2.email, primary: false, verified: false, visibility: "private" },
|
||||
],
|
||||
)
|
||||
|
||||
post "/auth/github/callback", params: {
|
||||
state: session["omniauth.state"],
|
||||
code: temp_code
|
||||
}
|
||||
post "/auth/github/callback", params: { state: session["omniauth.state"], code: temp_code }
|
||||
expect(response.status).to eq(302)
|
||||
expect(response.location).to eq("http://test.localhost/")
|
||||
expect(session[:current_user_id]).to be_blank
|
||||
@ -148,25 +132,12 @@ describe 'GitHub Oauth2' do
|
||||
|
||||
setup_github_emails_stub(
|
||||
[
|
||||
{
|
||||
email: user1.email,
|
||||
primary: true,
|
||||
verified: false,
|
||||
visibility: "private"
|
||||
},
|
||||
{
|
||||
email: user2.email,
|
||||
primary: false,
|
||||
verified: true,
|
||||
visibility: "private"
|
||||
}
|
||||
]
|
||||
{ email: user1.email, primary: true, verified: false, visibility: "private" },
|
||||
{ email: user2.email, primary: false, verified: true, visibility: "private" },
|
||||
],
|
||||
)
|
||||
|
||||
post "/auth/github/callback", params: {
|
||||
state: session["omniauth.state"],
|
||||
code: temp_code
|
||||
}
|
||||
post "/auth/github/callback", params: { state: session["omniauth.state"], code: temp_code }
|
||||
expect(response.status).to eq(302)
|
||||
expect(response.location).to eq("http://test.localhost/")
|
||||
expect(session[:current_user_id]).to eq(user2.id)
|
||||
@ -183,21 +154,13 @@ describe 'GitHub Oauth2' do
|
||||
email: "somerandomemail@discourse.org",
|
||||
primary: true,
|
||||
verified: true,
|
||||
visibility: "private"
|
||||
visibility: "private",
|
||||
},
|
||||
{
|
||||
email: user2.email,
|
||||
primary: false,
|
||||
verified: false,
|
||||
visibility: "private"
|
||||
}
|
||||
]
|
||||
{ email: user2.email, primary: false, verified: false, visibility: "private" },
|
||||
],
|
||||
)
|
||||
|
||||
post "/auth/github/callback", params: {
|
||||
state: session["omniauth.state"],
|
||||
code: temp_code
|
||||
}
|
||||
post "/auth/github/callback", params: { state: session["omniauth.state"], code: temp_code }
|
||||
expect(response.status).to eq(302)
|
||||
expect(response.location).to eq("http://test.localhost/")
|
||||
expect(session[:current_user_id]).to be_blank
|
||||
@ -210,25 +173,12 @@ describe 'GitHub Oauth2' do
|
||||
|
||||
setup_github_emails_stub(
|
||||
[
|
||||
{
|
||||
email: user1.email,
|
||||
primary: true,
|
||||
verified: true,
|
||||
visibility: "private"
|
||||
},
|
||||
{
|
||||
email: user2.email,
|
||||
primary: false,
|
||||
verified: true,
|
||||
visibility: "private"
|
||||
}
|
||||
]
|
||||
{ email: user1.email, primary: true, verified: true, visibility: "private" },
|
||||
{ email: user2.email, primary: false, verified: true, visibility: "private" },
|
||||
],
|
||||
)
|
||||
|
||||
post "/auth/github/callback", params: {
|
||||
state: session["omniauth.state"],
|
||||
code: temp_code
|
||||
}
|
||||
post "/auth/github/callback", params: { state: session["omniauth.state"], code: temp_code }
|
||||
expect(response.status).to eq(302)
|
||||
expect(response.location).to eq("http://test.localhost/")
|
||||
expect(session[:current_user_id]).to eq(user1.id)
|
||||
|
Reference in New Issue
Block a user