DEV: Introduce syntax_tree for ruby formatting (#63)
This commit is contained in:
parent
790d3311b0
commit
274a6496b1
|
@ -55,3 +55,12 @@ jobs:
|
||||||
- name: Rubocop
|
- name: Rubocop
|
||||||
if: ${{ !cancelled() }}
|
if: ${{ !cancelled() }}
|
||||||
run: bundle exec rubocop .
|
run: bundle exec rubocop .
|
||||||
|
|
||||||
|
- name: Syntax Tree
|
||||||
|
if: ${{ !cancelled() }}
|
||||||
|
run: |
|
||||||
|
if test -f .streerc; then
|
||||||
|
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
|
||||||
|
else
|
||||||
|
echo "Stree config not detected for this repository. Skipping."
|
||||||
|
fi
|
||||||
|
|
|
@ -80,7 +80,7 @@ jobs:
|
||||||
|
|
||||||
- name: Get yarn cache directory
|
- name: Get yarn cache directory
|
||||||
id: yarn-cache-dir
|
id: yarn-cache-dir
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Yarn cache
|
- name: Yarn cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
|
@ -130,7 +130,7 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
|
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
|
||||||
echo "::set-output name=files_exist::true"
|
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Plugin RSpec
|
- name: Plugin RSpec
|
||||||
|
@ -142,7 +142,7 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
||||||
echo "::set-output name=files_exist::true"
|
echo "files_exist=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Plugin QUnit
|
- name: Plugin QUnit
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
inherit_gem:
|
inherit_gem:
|
||||||
rubocop-discourse: default.yml
|
rubocop-discourse: stree-compat.yml
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -4,4 +4,5 @@ source "https://rubygems.org"
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem "rubocop-discourse"
|
gem "rubocop-discourse"
|
||||||
|
gem "syntax_tree"
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ GEM
|
||||||
parallel (1.22.1)
|
parallel (1.22.1)
|
||||||
parser (3.1.2.1)
|
parser (3.1.2.1)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
|
prettier_print (1.2.0)
|
||||||
rainbow (3.1.1)
|
rainbow (3.1.1)
|
||||||
regexp_parser (2.6.0)
|
regexp_parser (2.6.0)
|
||||||
rexml (3.2.5)
|
rexml (3.2.5)
|
||||||
|
@ -27,6 +28,8 @@ GEM
|
||||||
rubocop-rspec (2.13.2)
|
rubocop-rspec (2.13.2)
|
||||||
rubocop (~> 1.33)
|
rubocop (~> 1.33)
|
||||||
ruby-progressbar (1.11.0)
|
ruby-progressbar (1.11.0)
|
||||||
|
syntax_tree (5.1.0)
|
||||||
|
prettier_print (>= 1.2.0)
|
||||||
unicode-display_width (2.3.0)
|
unicode-display_width (2.3.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
@ -34,6 +37,7 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
rubocop-discourse
|
rubocop-discourse
|
||||||
|
syntax_tree
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.1.4
|
2.1.4
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator
|
class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator
|
||||||
def name
|
def name
|
||||||
'steam'
|
"steam"
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
|
@ -14,9 +14,11 @@ class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_middleware(omniauth)
|
def register_middleware(omniauth)
|
||||||
omniauth.provider :steam, setup: lambda { |env|
|
omniauth.provider :steam,
|
||||||
strategy = env["omniauth.strategy"]
|
setup:
|
||||||
strategy.options[:api_key] = SiteSetting.steam_web_api_key
|
lambda { |env|
|
||||||
}
|
strategy = env["omniauth.strategy"]
|
||||||
|
strategy.options[:api_key] = SiteSetting.steam_web_api_key
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,14 +6,14 @@ class EnableSteamLoginsValidator
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_value?(val)
|
def valid_value?(val)
|
||||||
return true if val == 'f'
|
return true if val == "f"
|
||||||
return false if SiteSetting.steam_web_api_key.blank?
|
return false if SiteSetting.steam_web_api_key.blank?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
if SiteSetting.steam_web_api_key.blank?
|
if SiteSetting.steam_web_api_key.blank?
|
||||||
I18n.t('site_settings.errors.steam_web_api_key_is_empty')
|
I18n.t("site_settings.errors.steam_web_api_key_is_empty")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
20
plugin.rb
20
plugin.rb
|
@ -6,21 +6,21 @@
|
||||||
# author: J. de Faye, tgxworld
|
# author: J. de Faye, tgxworld
|
||||||
|
|
||||||
# omniauth-openid is not included in core since v2.4.0.beta10
|
# omniauth-openid is not included in core since v2.4.0.beta10
|
||||||
unless defined? OmniAuth::Strategies::OpenID
|
unless defined?(OmniAuth::Strategies::OpenID)
|
||||||
gem 'ruby-openid', '2.9.2', require: false
|
gem "ruby-openid", "2.9.2", require: false
|
||||||
gem 'rack-openid', '1.3.1', require: false
|
gem "rack-openid", "1.3.1", require: false
|
||||||
gem 'omniauth-openid', '1.0.1'
|
gem "omniauth-openid", "1.0.1"
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'omniauth-steam', '1.0.6'
|
gem "omniauth-steam", "1.0.6"
|
||||||
|
|
||||||
register_svg_icon "fab-steam" if respond_to?(:register_svg_icon)
|
register_svg_icon "fab-steam" if respond_to?(:register_svg_icon)
|
||||||
|
|
||||||
register_asset 'stylesheets/steam-login.scss'
|
register_asset "stylesheets/steam-login.scss"
|
||||||
|
|
||||||
[
|
%w[
|
||||||
"../lib/auth/steam_authenticator.rb",
|
../lib/auth/steam_authenticator.rb
|
||||||
"../lib/validators/enable_steam_logins_validator.rb"
|
../lib/validators/enable_steam_logins_validator.rb
|
||||||
].each { |path| load File.expand_path(path, __FILE__) }
|
].each { |path| load File.expand_path(path, __FILE__) }
|
||||||
|
|
||||||
auth_provider authenticator: Auth::SteamAuthenticator.new, icon: 'fab-steam'
|
auth_provider authenticator: Auth::SteamAuthenticator.new, icon: "fab-steam"
|
||||||
|
|
|
@ -1,36 +1,34 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require "rails_helper"
|
||||||
|
|
||||||
RSpec.describe EnableSteamLoginsValidator do
|
RSpec.describe EnableSteamLoginsValidator do
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
describe '#valid_value?' do
|
describe "#valid_value?" do
|
||||||
describe 'when steam_web_api_key has not been set' do
|
describe "when steam_web_api_key has not been set" do
|
||||||
it "should return true when value is false" do
|
it "should return true when value is false" do
|
||||||
expect(subject.valid_value?('f')).to eq(true)
|
expect(subject.valid_value?("f")).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false when value is true" do
|
it "should return false when value is true" do
|
||||||
expect(subject.valid_value?('t')).to eq(false)
|
expect(subject.valid_value?("t")).to eq(false)
|
||||||
|
|
||||||
expect(subject.error_message).to eq(I18n.t(
|
expect(subject.error_message).to eq(
|
||||||
'site_settings.errors.steam_web_api_key_is_empty'
|
I18n.t("site_settings.errors.steam_web_api_key_is_empty"),
|
||||||
))
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when steam_web_api_key has been set' do
|
describe "when steam_web_api_key has been set" do
|
||||||
before do
|
before { SiteSetting.steam_web_api_key = "somekey" }
|
||||||
SiteSetting.steam_web_api_key = "somekey"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return true when value is false" do
|
it "should return true when value is false" do
|
||||||
expect(subject.valid_value?('f')).to eq(true)
|
expect(subject.valid_value?("f")).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return true when value is true' do
|
it "should return true when value is true" do
|
||||||
expect(subject.valid_value?('t')).to eq(true)
|
expect(subject.valid_value?("t")).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe 'Steam OpenID 2.0' do
|
describe "Steam OpenID 2.0" do
|
||||||
let(:web_api_key) { "abcdef11223344" }
|
let(:web_api_key) { "abcdef11223344" }
|
||||||
let(:steam_user_id) { "894923402340234" }
|
let(:steam_user_id) { "894923402340234" }
|
||||||
|
|
||||||
|
@ -11,16 +11,12 @@ describe 'Steam OpenID 2.0' do
|
||||||
SiteSetting.enable_steam_logins = true
|
SiteSetting.enable_steam_logins = true
|
||||||
|
|
||||||
cert = OpenSSL::X509::Certificate.new
|
cert = OpenSSL::X509::Certificate.new
|
||||||
cert.add_extension(OpenSSL::X509::Extension.new(
|
cert.add_extension(OpenSSL::X509::Extension.new("subjectAltName", "DNS:steamcommunity.com"))
|
||||||
"subjectAltName",
|
|
||||||
"DNS:steamcommunity.com"
|
|
||||||
))
|
|
||||||
StubSocket::StubIO.any_instance.stubs(:peer_cert).returns(cert)
|
StubSocket::StubIO.any_instance.stubs(:peer_cert).returns(cert)
|
||||||
|
|
||||||
stub_request(:get, "http://steamcommunity.com/openid")
|
stub_request(:get, "http://steamcommunity.com/openid").to_return(
|
||||||
.to_return(
|
status: 200,
|
||||||
status: 200,
|
body: <<~XML,
|
||||||
body: <<~XML,
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
|
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
|
||||||
<XRD>
|
<XRD>
|
||||||
|
@ -31,25 +27,23 @@ describe 'Steam OpenID 2.0' do
|
||||||
</XRD>
|
</XRD>
|
||||||
</xrds:XRDS>
|
</xrds:XRDS>
|
||||||
XML
|
XML
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type" => "text/xml"
|
"Content-Type" => "text/xml",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
stub_request(:post, "https://steamcommunity.com/openid/login")
|
stub_request(:post, "https://steamcommunity.com/openid/login").to_return(
|
||||||
.to_return(
|
status: 200,
|
||||||
status: 200,
|
body: <<~BODY,
|
||||||
body: <<~BODY,
|
|
||||||
ns:http://specs.openid.net/auth/2.0
|
ns:http://specs.openid.net/auth/2.0
|
||||||
is_valid:true
|
is_valid:true
|
||||||
BODY
|
BODY
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type" => "text/plain"
|
"Content-Type" => "text/plain",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
stub_request(:get, "https://steamcommunity.com/openid/id/#{steam_user_id}")
|
stub_request(:get, "https://steamcommunity.com/openid/id/#{steam_user_id}").to_return(
|
||||||
.to_return(
|
status: 200,
|
||||||
status: 200,
|
body: <<~BODY,
|
||||||
body: <<~BODY
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
|
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
|
||||||
<XRD>
|
<XRD>
|
||||||
|
@ -60,16 +54,14 @@ describe 'Steam OpenID 2.0' do
|
||||||
</XRD>
|
</XRD>
|
||||||
</xrds:XRDS>
|
</xrds:XRDS>
|
||||||
BODY
|
BODY
|
||||||
)
|
)
|
||||||
stub_request(:get, "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=#{web_api_key}&steamids=#{steam_user_id}")
|
stub_request(
|
||||||
.with(
|
:get,
|
||||||
headers: {
|
"https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=#{web_api_key}&steamids=#{steam_user_id}",
|
||||||
"Host" => "api.steampowered.com"
|
).with(headers: { "Host" => "api.steampowered.com" }).to_return(
|
||||||
}
|
status: 200,
|
||||||
)
|
body:
|
||||||
.to_return(
|
JSON.dump(
|
||||||
status: 200,
|
|
||||||
body: JSON.dump(
|
|
||||||
response: {
|
response: {
|
||||||
players: [
|
players: [
|
||||||
{
|
{
|
||||||
|
@ -78,20 +70,23 @@ describe 'Steam OpenID 2.0' do
|
||||||
profilestate: 1,
|
profilestate: 1,
|
||||||
personaname: "SteamyPlayer",
|
personaname: "SteamyPlayer",
|
||||||
profileurl: "https://steamcommunity.com/id/SteamyPlayer/",
|
profileurl: "https://steamcommunity.com/id/SteamyPlayer/",
|
||||||
avatar: "https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d.jpg",
|
avatar:
|
||||||
avatarmedium: "https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d_medium.jpg",
|
"https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d.jpg",
|
||||||
avatarfull: "https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d_full.jpg",
|
avatarmedium:
|
||||||
|
"https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d_medium.jpg",
|
||||||
|
avatarfull:
|
||||||
|
"https://avatars.akamai.steamstatic.com/734096e84a118c839422fa213faa6885c093374d_full.jpg",
|
||||||
avatarhash: "734096e84a118c839422fa213faa6885c093374d",
|
avatarhash: "734096e84a118c839422fa213faa6885c093374d",
|
||||||
lastlogoff: 1659365725,
|
lastlogoff: 1_659_365_725,
|
||||||
personastate: 0,
|
personastate: 0,
|
||||||
primaryclanid: "103588791859221341",
|
primaryclanid: "103588791859221341",
|
||||||
timecreated: 1524883291,
|
timecreated: 1_524_883_291,
|
||||||
personastateflags: 0
|
personastateflags: 0,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "retrieves user details from the Steam API after the authentication flow is complete" do
|
it "retrieves user details from the Steam API after the authentication flow is complete" do
|
||||||
|
@ -99,19 +94,21 @@ describe 'Steam OpenID 2.0' do
|
||||||
expect(response.status).to eq(303)
|
expect(response.status).to eq(303)
|
||||||
expect(response.location).to start_with("https://steamcommunity.com/openid/login")
|
expect(response.location).to start_with("https://steamcommunity.com/openid/login")
|
||||||
|
|
||||||
post "/auth/steam/callback", params: {
|
post "/auth/steam/callback",
|
||||||
_method: "post",
|
params: {
|
||||||
"openid.ns": "http://specs.openid.net/auth/2.0",
|
_method: "post",
|
||||||
"openid.mode": "id_res",
|
"openid.ns": "http://specs.openid.net/auth/2.0",
|
||||||
"openid.op_endpoint": "https://steamcommunity.com/openid/login",
|
"openid.mode": "id_res",
|
||||||
"openid.claimed_id": "https://steamcommunity.com/openid/id/#{steam_user_id}",
|
"openid.op_endpoint": "https://steamcommunity.com/openid/login",
|
||||||
"openid.identity": "https://steamcommunity.com/openid/id/#{steam_user_id}",
|
"openid.claimed_id": "https://steamcommunity.com/openid/id/#{steam_user_id}",
|
||||||
"openid.return_to": "http://test.localhost/auth/steam/callback?_method=post",
|
"openid.identity": "https://steamcommunity.com/openid/id/#{steam_user_id}",
|
||||||
"openid.response_nonce": "#{1.minute.ago.iso8601}aZq7eHv92/2Mg4OsPKiKcTgI0j4=",
|
"openid.return_to": "http://test.localhost/auth/steam/callback?_method=post",
|
||||||
"openid.assoc_handle": "1234567890",
|
"openid.response_nonce": "#{1.minute.ago.iso8601}aZq7eHv92/2Mg4OsPKiKcTgI0j4=",
|
||||||
"openid.signed": "signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle",
|
"openid.assoc_handle": "1234567890",
|
||||||
"openid.sig": "ZseI1sqVHGU/f5Ye7Tcn7T3QMIg=",
|
"openid.signed":
|
||||||
}
|
"signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle",
|
||||||
|
"openid.sig": "ZseI1sqVHGU/f5Ye7Tcn7T3QMIg=",
|
||||||
|
}
|
||||||
expect(response.status).to eq(302)
|
expect(response.status).to eq(302)
|
||||||
expect(response.location).to eq("http://test.localhost/")
|
expect(response.location).to eq("http://test.localhost/")
|
||||||
expect(session[:current_user_id]).to be_blank
|
expect(session[:current_user_id]).to be_blank
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Auth::SteamAuthenticator do
|
describe Auth::SteamAuthenticator do
|
||||||
describe '#can_revoke?' do
|
describe "#can_revoke?" do
|
||||||
it 'should be false be default' do
|
it "should be false be default" do
|
||||||
authenticator = Auth::SteamAuthenticator.new
|
authenticator = Auth::SteamAuthenticator.new
|
||||||
|
|
||||||
expect(authenticator.can_revoke?).to eq(false)
|
expect(authenticator.can_revoke?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be true when steam_logins_allow_revoke site settings is enabled' do
|
it "should be true when steam_logins_allow_revoke site settings is enabled" do
|
||||||
SiteSetting.steam_logins_allow_revoke = true
|
SiteSetting.steam_logins_allow_revoke = true
|
||||||
|
|
||||||
authenticator = Auth::SteamAuthenticator.new
|
authenticator = Auth::SteamAuthenticator.new
|
||||||
|
|
Loading…
Reference in New Issue