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