Skip to content

Commit 5ef6285

Browse files
committed
👷 Spec fixes and linting
1 parent 1680fda commit 5ef6285

17 files changed

+1364
-1278
lines changed

.gitlab-ci.yml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
default:
22
image: ruby:3.2
33

4+
variables:
5+
BUNDLE_INSTALL_FLAGS: "--quiet --jobs=$(nproc) --retry=3"
6+
BUNDLE_FROZEN: "false" # No lockfile!
7+
BUNDLE_GEMFILE: gemfiles/omnibus.gemfile
8+
K_SOUP_COV_DEBUG: true
9+
K_SOUP_COV_DO: true
10+
K_SOUP_COV_HARD: true
11+
K_SOUP_COV_MIN_BRANCH: 46
12+
K_SOUP_COV_MIN_LINE: 93
13+
K_SOUP_COV_VERBOSE: true
14+
K_SOUP_COV_FORMATTERS: "html,xml,rcov,lcov,json,tty"
15+
K_SOUP_COV_MULTI_FORMATTERS: true
16+
K_SOUP_COV_COMMAND_NAME: "RSpec Coverage"
17+
418
workflow:
519
rules:
620
# For merge requests, create a pipeline.
@@ -16,7 +30,20 @@ workflow:
1630
script:
1731
- gem update --system > /dev/null 2>&1
1832
- bundle config --local path vendor
19-
- bundle install --quiet --jobs 4 --retry 3
33+
- bundle install
34+
- bundle exec rake test
35+
cache:
36+
key: ${CI_JOB_IMAGE}
37+
paths:
38+
- vendor/ruby
39+
40+
.test_template-eol: &test_definition-eol
41+
image: ruby:${RUBY_VERSION}
42+
stage: test
43+
script:
44+
- gem update --system > /dev/null 2>&1
45+
- bundle config --local path vendor
46+
- bundle install
2047
- bundle exec rake test
2148
cache:
2249
key: ${CI_JOB_IMAGE}
@@ -32,7 +59,7 @@ workflow:
3259
# Actually updates both RubyGems and Bundler!
3360
- update_rubygems > /dev/null 2>&1
3461
- bundle config --local path vendor
35-
- bundle install --quiet --jobs 4 --retry 3
62+
- bundle install
3663
- bundle exec rake test
3764
cache:
3865
key: ${CI_JOB_IMAGE}
@@ -43,7 +70,13 @@ ruby-current:
4370
<<: *test_definition-current
4471
parallel:
4572
matrix:
46-
- RUBY_VERSION: ["3.0", "3.1", "3.2"]
73+
- RUBY_VERSION: ["3.1", "3.2", "3.3", "3.4"]
74+
75+
ruby-eol:
76+
<<: *test_definition-eol
77+
parallel:
78+
matrix:
79+
- RUBY_VERSION: ["3.0"]
4780

4881
ruby-legacy:
4982
<<: *test_definition-legacy

.rspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
--format documentation
2-
--require spec_helper
32
--color
3+
--require spec_helper
44
--order random

spec/examples/google_spec.rb

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
# frozen_string_literal: true
22

3-
require 'jwt'
3+
require "jwt"
44

5-
RSpec.describe 'using OAuth2 with Google' do
5+
RSpec.describe "using OAuth2 with Google" do
66
# This describes authenticating to a Google API via a service account.
77
# See their docs: https://developers.google.com/identity/protocols/OAuth2ServiceAccount
88

9-
describe 'via 2-legged JWT assertion' do
9+
describe "via 2-legged JWT assertion" do
1010
let(:client) do
1111
OAuth2::Client.new(
12-
'',
13-
'',
14-
site: 'https://accounts.google.com',
15-
authorize_url: '/o/oauth2/auth',
16-
token_url: '/o/oauth2/token',
17-
auth_scheme: :request_body
12+
"",
13+
"",
14+
site: "https://accounts.google.com",
15+
authorize_url: "/o/oauth2/auth",
16+
token_url: "/o/oauth2/token",
17+
auth_scheme: :request_body,
1818
)
1919
end
2020

2121
# These are taken directly from Google's documentation example:
2222

2323
let(:required_claims) do
2424
{
25-
'iss' => '761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com',
25+
"iss" => "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
2626
# The email address of the service account.
2727

28-
'scope' => 'https://www.googleapis.com/auth/devstorage.readonly https://www.googleapis.com/auth/prediction',
28+
"scope" => "https://www.googleapis.com/auth/devstorage.readonly https://www.googleapis.com/auth/prediction",
2929
# A space-delimited list of the permissions that the application requests.
3030

31-
'aud' => 'https://www.googleapis.com/oauth2/v4/token',
31+
"aud" => "https://www.googleapis.com/oauth2/v4/token",
3232
# A descriptor of the intended target of the assertion. When making an access token request this value
3333
# is always https://www.googleapis.com/oauth2/v4/token.
3434

35-
'exp' => Time.now.to_i + 3600,
35+
"exp" => Time.now.to_i + 3600,
3636
# The expiration time of the assertion, specified as seconds since 00:00:00 UTC, January 1, 1970. This value
3737
# has a maximum of 1 hour after the issued time.
3838

39-
'iat' => Time.now.to_i,
39+
"iat" => Time.now.to_i,
4040
# The time the assertion was issued, specified as seconds since 00:00:00 UTC, January 1, 1970.
4141
}
4242
end
4343

4444
let(:optional_claims) do
4545
{
46-
'sub' => 'some.user@example.com',
46+
"sub" => "some.user@example.com",
4747
# The email address of the user for which the application is requesting delegated access.
4848
}
4949
end
5050

51-
let(:algorithm) { 'RS256' }
51+
let(:algorithm) { "RS256" }
5252
# Per Google: "Service accounts rely on the RSA SHA-256 algorithm"
5353

5454
let(:key) do
5555
begin
56-
OpenSSL::PKCS12.new(File.read('spec/fixtures/google_service_account_key.p12'), 'notasecret').key
56+
OpenSSL::PKCS12.new(File.read("spec/fixtures/google_service_account_key.p12"), "notasecret").key
5757
# This simulates the .p12 file that Google gives you to download and keep somewhere. This is meant to
5858
# illustrate extracting the key and using it to generate the JWT.
5959
rescue OpenSSL::PKCS12::PKCS12Error
@@ -73,39 +73,39 @@
7373
client.connection = Faraday.new(client.site, client.options[:connection_opts]) do |builder|
7474
builder.request :url_encoded
7575
builder.adapter :test do |stub|
76-
stub.post('https://accounts.google.com/o/oauth2/token') do |token_request|
76+
stub.post("https://accounts.google.com/o/oauth2/token") do |token_request|
7777
@request_body = Rack::Utils.parse_nested_query(token_request.body).transform_keys(&:to_sym)
7878

7979
[
8080
200,
8181

8282
{
83-
'Content-Type' => 'application/json',
83+
"Content-Type" => "application/json",
8484
},
8585

8686
{
87-
'access_token' => '1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M',
88-
'token_type' => 'Bearer',
89-
'expires_in' => 3600,
87+
"access_token" => "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
88+
"token_type" => "Bearer",
89+
"expires_in" => 3600,
9090
}.to_json,
9191
]
9292
end
9393
end
9494
end
9595
end
9696

97-
context 'when passing the required claims' do
97+
context "when passing the required claims" do
9898
let(:claims) { required_claims }
9999

100-
it 'sends a JWT with the 5 keys' do
100+
it "sends a JWT with the 5 keys" do
101101
client.assertion.get_token(claims, encoding_options)
102102

103-
expect(@request_body).not_to be_nil, 'No access token request was made!'
104-
expect(@request_body[:grant_type]).to eq('urn:ietf:params:oauth:grant-type:jwt-bearer')
103+
expect(@request_body).not_to be_nil, "No access token request was made!"
104+
expect(@request_body[:grant_type]).to eq("urn:ietf:params:oauth:grant-type:jwt-bearer")
105105
expect(@request_body[:assertion]).to be_a(String)
106106

107107
payload, header = JWT.decode(@request_body[:assertion], key, true, algorithm: algorithm)
108-
expect(header['alg']).to eq('RS256')
108+
expect(header["alg"]).to eq("RS256")
109109
expect(payload.keys).to match_array(%w[iss scope aud exp iat])
110110

111111
# Note that these specifically do _not_ include the 'sub' claim, which is indicated as being 'required'
@@ -118,18 +118,18 @@
118118
end
119119
end
120120

121-
context 'when including the optional `sub` claim' do
121+
context "when including the optional `sub` claim" do
122122
let(:claims) { required_claims.merge(optional_claims) }
123123

124-
it 'sends a JWT with the 6 keys' do
124+
it "sends a JWT with the 6 keys" do
125125
client.assertion.get_token(claims, encoding_options)
126126

127-
expect(@request_body).not_to be_nil, 'No access token request was made!'
128-
expect(@request_body[:grant_type]).to eq('urn:ietf:params:oauth:grant-type:jwt-bearer')
127+
expect(@request_body).not_to be_nil, "No access token request was made!"
128+
expect(@request_body[:grant_type]).to eq("urn:ietf:params:oauth:grant-type:jwt-bearer")
129129
expect(@request_body[:assertion]).to be_a(String)
130130

131131
payload, header = JWT.decode(@request_body[:assertion], key, true, algorithm: algorithm)
132-
expect(header['alg']).to eq('RS256')
132+
expect(header["alg"]).to eq("RS256")
133133
expect(payload.keys).to match_array(%w[iss scope aud exp iat sub])
134134

135135
payload.each do |key, value|

spec/ext/backports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# frozen_string_literal: true
22

3-
require 'backports/2.5.0/hash/transform_keys'
3+
require "backports/2.5.0/hash/transform_keys"

0 commit comments

Comments
 (0)