omniauth-v2-ynab 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/tests/release_contract.py +269 -0
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/release.yml +75 -21
- data/Gemfile +1 -1
- data/lib/omniauth/strategies/ynab.rb +1 -0
- data/lib/omniauth-v2-ynab/version.rb +1 -1
- data/spec/omniauth/strategies/ynab_csrf_spec.rb +83 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3f33a1a73ee9dd96d3c19e9b35b8b3268cf337e1525eb1a559062e8cdf956f0
|
|
4
|
+
data.tar.gz: b27792ffd28db8d99966c685784ae6a5e0081801e3009405125a84b593a5080e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd19a0795a12206f9cca82b1dd99fc394b91d6132f8b9a01a87259c6649ad8f37610fe7ce3053c5856d4a2b296c16b7c1c094bdbc066e7399d3203df3fd29ad4
|
|
7
|
+
data.tar.gz: daed1ecf404f3f420de8cc80b831fccec60e206019a05d5b535b8fd036d6d956ed1697fc40a6f0265ec71534ab6cd8911f71517fc09d4f4f508b75d4ee60bd73
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"""Run real release shell steps against local git and mocked publication APIs.
|
|
2
|
+
|
|
3
|
+
Requires Ruby (standard-library YAML/JSON) and Python 3. No production credentials.
|
|
4
|
+
"""
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import shlex
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
import subprocess
|
|
11
|
+
import tempfile
|
|
12
|
+
import unittest
|
|
13
|
+
|
|
14
|
+
WORKFLOW = Path(os.environ.get("RELEASE_WORKFLOW", ".github/workflows/release.yml")).resolve()
|
|
15
|
+
WORKFLOW_DATA = json.loads(subprocess.check_output([
|
|
16
|
+
"ruby", "-ryaml", "-rjson", "-e",
|
|
17
|
+
"puts JSON.generate(YAML.load_file(ARGV[0]))", str(WORKFLOW),
|
|
18
|
+
], text=True))
|
|
19
|
+
STEPS = {step.get("name"): step for step in WORKFLOW_DATA["jobs"]["release"]["steps"]}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ReleaseContract(unittest.TestCase):
|
|
23
|
+
def setUp(self):
|
|
24
|
+
self.temp = tempfile.TemporaryDirectory()
|
|
25
|
+
self.addCleanup(self.temp.cleanup)
|
|
26
|
+
self.root = Path(self.temp.name)
|
|
27
|
+
self.repo = self.root / "repo"
|
|
28
|
+
self.remote = self.root / "remote.git"
|
|
29
|
+
self.repo.mkdir()
|
|
30
|
+
self.bin = self.root / "bin"
|
|
31
|
+
self.bin.mkdir()
|
|
32
|
+
self.output = self.root / "output"
|
|
33
|
+
self.output.touch()
|
|
34
|
+
self.summary = self.root / "summary"
|
|
35
|
+
self.calls = self.root / "calls"
|
|
36
|
+
self.pr = self.root / "pr"
|
|
37
|
+
self.env = dict(os.environ, PATH=str(self.bin) + ":" + os.environ["PATH"],
|
|
38
|
+
GITHUB_OUTPUT=str(self.output), GITHUB_STEP_SUMMARY=str(self.summary),
|
|
39
|
+
CALLS=str(self.calls), PR_FILE=str(self.pr), VERSION="2.3.0",
|
|
40
|
+
VERSIONS='[{"number": "2.2.0"}, {"number": "2.3.0"}]',
|
|
41
|
+
CURL_FAIL="0", PR_DENIED="0",
|
|
42
|
+
JOB_PULL_REQUESTS=WORKFLOW_DATA["jobs"]["release"].get(
|
|
43
|
+
"permissions", {}).get("pull-requests", "none"))
|
|
44
|
+
self.mock("curl", 'if [ "$CURL_FAIL" = 1 ]; then exit 22; fi\nprintf "%s" "$VERSIONS"\n')
|
|
45
|
+
self.mock("gem", 'echo "gem $*" >> "$CALLS"\n')
|
|
46
|
+
self.mock("gh", '''echo "gh $*" >> "$CALLS"
|
|
47
|
+
case "$1 $2" in
|
|
48
|
+
"pr list") if [ -f "$PR_FILE" ]; then cat "$PR_FILE"; fi ;;
|
|
49
|
+
"pr create")
|
|
50
|
+
if [ "$JOB_PULL_REQUESTS" != write ]; then exit 77; fi
|
|
51
|
+
if [ "$PR_DENIED" = 1 ]; then exit 1; fi
|
|
52
|
+
echo https://example.test/pr/1 > "$PR_FILE" ;;
|
|
53
|
+
"release create") ;;
|
|
54
|
+
*) exit 99 ;;
|
|
55
|
+
esac
|
|
56
|
+
''')
|
|
57
|
+
self.git("init", "-b", "main")
|
|
58
|
+
self.git("config", "user.name", "Contract")
|
|
59
|
+
self.git("config", "user.email", "contract@example.test")
|
|
60
|
+
self.version("2.2.0")
|
|
61
|
+
(self.repo / "README.md").write_text("initial\n")
|
|
62
|
+
self.commit("base")
|
|
63
|
+
self.git("tag", "v2.2.0")
|
|
64
|
+
subprocess.run(["git", "init", "--bare", str(self.remote)], check=True,
|
|
65
|
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
66
|
+
self.git("remote", "add", "origin", str(self.remote))
|
|
67
|
+
self.git("push", "origin", "main", "--tags")
|
|
68
|
+
hook = self.remote / "hooks/pre-receive"
|
|
69
|
+
hook.write_text('#!/bin/sh\nwhile read old new ref; do\n'
|
|
70
|
+
'if [ "$ref" = refs/heads/main ]; then echo GH013 >&2; exit 1; fi\ndone\n')
|
|
71
|
+
hook.chmod(0o755)
|
|
72
|
+
|
|
73
|
+
def mock(self, name, content):
|
|
74
|
+
path = self.bin / name
|
|
75
|
+
path.write_text("#!/bin/bash\nset -eu\n" + content)
|
|
76
|
+
path.chmod(0o755)
|
|
77
|
+
|
|
78
|
+
def git(self, *args):
|
|
79
|
+
return subprocess.check_output(["git", *args], cwd=self.repo, env=self.env,
|
|
80
|
+
stderr=subprocess.STDOUT, text=True).strip()
|
|
81
|
+
|
|
82
|
+
def version(self, version):
|
|
83
|
+
path = self.repo / "lib/omniauth-v2-ynab/version.rb"
|
|
84
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
85
|
+
path.write_text('module OmniAuth\n module YNAB\n VERSION = "' + version + '".freeze\n end\nend\n')
|
|
86
|
+
|
|
87
|
+
def commit(self, message):
|
|
88
|
+
self.git("add", ".")
|
|
89
|
+
self.git("commit", "-m", message)
|
|
90
|
+
|
|
91
|
+
def run_step(self, name, success=True):
|
|
92
|
+
script = STEPS[name]["run"].replace("${{ steps.version.outputs.version }}", self.env["VERSION"])
|
|
93
|
+
result = subprocess.run(["bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", script],
|
|
94
|
+
cwd=self.repo, env=self.env, text=True, capture_output=True)
|
|
95
|
+
if success:
|
|
96
|
+
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
97
|
+
else:
|
|
98
|
+
self.assertNotEqual(result.returncode, 0)
|
|
99
|
+
return result
|
|
100
|
+
|
|
101
|
+
def publish(self):
|
|
102
|
+
if self.outputs().get("publish") == "true":
|
|
103
|
+
self.env["VERSION"] = self.outputs()["version"]
|
|
104
|
+
for name in ["Build gem", "Push to RubyGems", "Tag release", "Create GitHub Release"]:
|
|
105
|
+
self.run_step(name)
|
|
106
|
+
|
|
107
|
+
def outputs(self):
|
|
108
|
+
return dict(line.split("=", 1) for line in self.output.read_text().splitlines())
|
|
109
|
+
|
|
110
|
+
def test_workflow_guards_and_permissions(self):
|
|
111
|
+
job = WORKFLOW_DATA["jobs"]["release"]
|
|
112
|
+
self.assertIn("github.event.workflow_run.event == 'push'", job["if"])
|
|
113
|
+
self.assertEqual(WORKFLOW_DATA["permissions"], {"contents": "write", "id-token": "write"})
|
|
114
|
+
self.assertEqual(job["permissions"],
|
|
115
|
+
{"contents": "write", "id-token": "write", "pull-requests": "write"})
|
|
116
|
+
self.assertEqual(set(WORKFLOW_DATA["jobs"]), {"release"})
|
|
117
|
+
workflow = WORKFLOW.read_text()
|
|
118
|
+
self.assertNotIn("write-all", workflow)
|
|
119
|
+
self.assertNotRegex(workflow, r"\bgh\s+pr\s+(review|merge)\b")
|
|
120
|
+
self.assertNotIn("--approve", workflow)
|
|
121
|
+
self.assertNotIn("--admin", workflow)
|
|
122
|
+
self.assertNotIn("--force", workflow)
|
|
123
|
+
self.assertNotRegex(workflow, r"\bgh\s+api\b")
|
|
124
|
+
allowed_pushes = [
|
|
125
|
+
["git", "push", "origin", "HEAD:refs/heads/$BRANCH"],
|
|
126
|
+
["git", "push", "origin", "v${{ steps.version.outputs.version }}"],
|
|
127
|
+
]
|
|
128
|
+
pushes = []
|
|
129
|
+
for step in job["steps"]:
|
|
130
|
+
for line in step.get("run", "").splitlines():
|
|
131
|
+
if re.match(r"\s*git\s+push\b", line):
|
|
132
|
+
args = shlex.split(line)
|
|
133
|
+
self.assertIn(args, allowed_pushes)
|
|
134
|
+
pushes.append(args)
|
|
135
|
+
self.assertCountEqual(pushes, allowed_pushes)
|
|
136
|
+
for name in ["Build gem", "Configure RubyGems credentials (OIDC)", "Push to RubyGems",
|
|
137
|
+
"Tag release", "Create GitHub Release"]:
|
|
138
|
+
self.assertEqual(STEPS[name]["if"], "steps.version.outputs.publish == 'true'")
|
|
139
|
+
self.assertEqual(STEPS["Resolve version"]["if"], "steps.changes.outputs.release == 'true'")
|
|
140
|
+
self.assertNotIn("HEAD:main", WORKFLOW.read_text())
|
|
141
|
+
|
|
142
|
+
def test_bookkeeping_squash_and_merge_are_skipped(self):
|
|
143
|
+
self.version("2.3.0")
|
|
144
|
+
path = self.repo / ".github/workflows/release.yml"
|
|
145
|
+
path.parent.mkdir(parents=True)
|
|
146
|
+
path.write_text(WORKFLOW.read_text())
|
|
147
|
+
self.commit("Repair release bookkeeping (#7)")
|
|
148
|
+
self.run_step("Check release changes")
|
|
149
|
+
self.assertEqual(self.outputs()["release"], "false")
|
|
150
|
+
self.git("switch", "-c", "bookkeeping")
|
|
151
|
+
self.version("2.4.0")
|
|
152
|
+
self.commit("bookkeeping")
|
|
153
|
+
self.git("switch", "main")
|
|
154
|
+
self.git("merge", "--no-ff", "bookkeeping", "-m", "Merge pull request")
|
|
155
|
+
self.run_step("Check release changes")
|
|
156
|
+
self.assertEqual(self.outputs()["release"], "false")
|
|
157
|
+
|
|
158
|
+
def test_real_changes_release(self):
|
|
159
|
+
(self.repo / "README.md").write_text("changed\n")
|
|
160
|
+
self.commit("normal change")
|
|
161
|
+
self.run_step("Check release changes")
|
|
162
|
+
self.assertEqual(self.outputs()["release"], "true")
|
|
163
|
+
|
|
164
|
+
def test_multiple_commits_cannot_hide_real_changes(self):
|
|
165
|
+
(self.repo / "README.md").write_text("real change before bookkeeping\n")
|
|
166
|
+
self.commit("feature")
|
|
167
|
+
self.version("2.3.0")
|
|
168
|
+
self.commit("last commit only changes version")
|
|
169
|
+
self.run_step("Check release changes")
|
|
170
|
+
self.assertEqual(self.outputs()["release"], "true")
|
|
171
|
+
|
|
172
|
+
def test_exact_released_source_is_skipped(self):
|
|
173
|
+
self.run_step("Check release changes")
|
|
174
|
+
self.assertEqual(self.outputs()["release"], "false")
|
|
175
|
+
|
|
176
|
+
def test_published_candidate_skips_all_publication(self):
|
|
177
|
+
self.run_step("Resolve version")
|
|
178
|
+
self.assertEqual(self.outputs(), {"version": "2.3.0", "bumped": "true", "publish": "false"})
|
|
179
|
+
self.publish()
|
|
180
|
+
self.assertFalse(self.calls.exists())
|
|
181
|
+
self.run_step("Propose version bookkeeping PR")
|
|
182
|
+
first = self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0")
|
|
183
|
+
self.run_step("Propose version bookkeeping PR")
|
|
184
|
+
self.assertEqual(first, self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0"))
|
|
185
|
+
calls = self.calls.read_text()
|
|
186
|
+
self.assertEqual(calls.count("gh pr create"), 1)
|
|
187
|
+
self.assertEqual(self.env["JOB_PULL_REQUESTS"], "write")
|
|
188
|
+
self.assertTrue(self.pr.exists())
|
|
189
|
+
self.assertNotIn("gh pr review", calls)
|
|
190
|
+
self.assertNotIn("gh pr merge", calls)
|
|
191
|
+
self.assertNotIn("gem push", calls)
|
|
192
|
+
self.assertNotIn("release create", calls)
|
|
193
|
+
self.assertEqual(self.git("ls-remote", "origin", "refs/heads/main").split()[0],
|
|
194
|
+
self.git("rev-parse", "main"))
|
|
195
|
+
|
|
196
|
+
def test_new_candidate_and_manual_version(self):
|
|
197
|
+
self.env["VERSIONS"] = '[{"number":"2.2.0"}]'
|
|
198
|
+
self.run_step("Resolve version")
|
|
199
|
+
self.assertEqual(self.outputs()["publish"], "true")
|
|
200
|
+
self.assertEqual(self.outputs()["version"], "2.3.0")
|
|
201
|
+
self.version("3.0.0")
|
|
202
|
+
self.run_step("Resolve version")
|
|
203
|
+
self.assertEqual(self.outputs(), {"version": "3.0.0", "bumped": "false", "publish": "true"})
|
|
204
|
+
|
|
205
|
+
def test_fresh_publication_then_same_source_retry(self):
|
|
206
|
+
self.env["VERSIONS"] = '[{"number":"2.2.0"}]'
|
|
207
|
+
source = self.git("rev-parse", "HEAD")
|
|
208
|
+
self.run_step("Resolve version")
|
|
209
|
+
self.publish()
|
|
210
|
+
self.assertEqual(self.calls.read_text().count("gem push"), 1)
|
|
211
|
+
self.assertTrue(self.git("ls-remote", "origin", "refs/tags/v2.3.0"))
|
|
212
|
+
self.git("restore", "--source=" + source, "--staged", "--worktree",
|
|
213
|
+
"lib/omniauth-v2-ynab/version.rb")
|
|
214
|
+
self.run_step("Resolve version")
|
|
215
|
+
self.publish()
|
|
216
|
+
self.assertEqual(self.calls.read_text().count("gem push"), 1)
|
|
217
|
+
self.assertEqual(self.calls.read_text().count("gh release create"), 1)
|
|
218
|
+
|
|
219
|
+
def test_correct_next_minor_after_bookkeeping(self):
|
|
220
|
+
self.version("2.3.0")
|
|
221
|
+
self.run_step("Resolve version")
|
|
222
|
+
self.assertEqual(self.outputs(), {"version": "2.4.0", "bumped": "true", "publish": "true"})
|
|
223
|
+
|
|
224
|
+
def test_tag_alone_prevents_repeat_publication(self):
|
|
225
|
+
self.env["VERSIONS"] = '[]'
|
|
226
|
+
self.git("tag", "v2.3.0")
|
|
227
|
+
self.run_step("Resolve version")
|
|
228
|
+
self.assertEqual(self.outputs()["publish"], "false")
|
|
229
|
+
|
|
230
|
+
def test_registry_failure_stops_before_publication(self):
|
|
231
|
+
self.env["CURL_FAIL"] = "1"
|
|
232
|
+
self.run_step("Resolve version", success=False)
|
|
233
|
+
self.assertEqual(self.outputs(), {})
|
|
234
|
+
self.assertFalse(self.calls.exists())
|
|
235
|
+
|
|
236
|
+
def test_denied_pr_preserves_ready_branch(self):
|
|
237
|
+
self.run_step("Resolve version")
|
|
238
|
+
self.env["JOB_PULL_REQUESTS"] = "read"
|
|
239
|
+
result = self.run_step("Propose version bookkeeping PR", success=False)
|
|
240
|
+
self.assertIn("GITHUB_TOKEN cannot create", result.stdout)
|
|
241
|
+
self.assertFalse(self.pr.exists())
|
|
242
|
+
ready = self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0")
|
|
243
|
+
self.env["JOB_PULL_REQUESTS"] = "write"
|
|
244
|
+
self.env["PR_DENIED"] = "1"
|
|
245
|
+
result = self.run_step("Propose version bookkeeping PR", success=False)
|
|
246
|
+
self.assertIn("GITHUB_TOKEN cannot create", result.stdout)
|
|
247
|
+
self.assertNotIn("Repository Actions PR creation is disabled", result.stdout)
|
|
248
|
+
self.assertNotIn("no pull-requests: write permission", result.stdout)
|
|
249
|
+
self.assertIn("release/bookkeeping-v2.3.0", self.summary.read_text())
|
|
250
|
+
self.assertEqual(ready, self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0"))
|
|
251
|
+
self.env["PR_DENIED"] = "0"
|
|
252
|
+
self.run_step("Propose version bookkeeping PR")
|
|
253
|
+
self.assertTrue(self.pr.exists())
|
|
254
|
+
self.assertEqual(ready, self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0"))
|
|
255
|
+
|
|
256
|
+
def test_other_writer_branch_is_not_overwritten(self):
|
|
257
|
+
self.git("switch", "-c", "other")
|
|
258
|
+
self.version("9.0.0")
|
|
259
|
+
self.commit("other writer")
|
|
260
|
+
self.git("push", "origin", "HEAD:refs/heads/release/bookkeeping-v2.3.0")
|
|
261
|
+
original = self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0")
|
|
262
|
+
self.git("switch", "main")
|
|
263
|
+
self.run_step("Resolve version")
|
|
264
|
+
self.run_step("Propose version bookkeeping PR", success=False)
|
|
265
|
+
self.assertEqual(original, self.git("ls-remote", "origin", "refs/heads/release/bookkeeping-v2.3.0"))
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
if __name__ == "__main__":
|
|
269
|
+
unittest.main(verbosity=2)
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -17,15 +17,20 @@ permissions:
|
|
|
17
17
|
|
|
18
18
|
jobs:
|
|
19
19
|
release:
|
|
20
|
+
permissions:
|
|
21
|
+
contents: write
|
|
22
|
+
id-token: write
|
|
23
|
+
pull-requests: write
|
|
20
24
|
# Only run when CI passed, and not on auto-bump commits (loop prevention).
|
|
21
25
|
if: |
|
|
22
26
|
github.event.workflow_run.conclusion == 'success' &&
|
|
27
|
+
github.event.workflow_run.event == 'push' &&
|
|
23
28
|
!startsWith(github.event.workflow_run.head_commit.message, '[auto] Bump version to')
|
|
24
29
|
runs-on: ubuntu-latest
|
|
25
30
|
environment: rubygems
|
|
26
31
|
|
|
27
32
|
steps:
|
|
28
|
-
- uses: actions/checkout@
|
|
33
|
+
- uses: actions/checkout@v7
|
|
29
34
|
with:
|
|
30
35
|
fetch-depth: 0
|
|
31
36
|
ref: ${{ github.event.workflow_run.head_sha }}
|
|
@@ -41,44 +46,71 @@ jobs:
|
|
|
41
46
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
42
47
|
git config user.name "github-actions[bot]"
|
|
43
48
|
|
|
49
|
+
# Version/release-maintenance PRs must not publish another gem when merged.
|
|
50
|
+
- name: Check release changes
|
|
51
|
+
id: changes
|
|
52
|
+
run: |
|
|
53
|
+
# Compare with the last released source, including all commits in a rebase merge.
|
|
54
|
+
RELEASE_BASE=$(git describe --tags --match 'v[0-9]*' --abbrev=0 HEAD)
|
|
55
|
+
CHANGED=$(git diff --name-only "$RELEASE_BASE" HEAD)
|
|
56
|
+
if [ -n "$CHANGED" ] && printf '%s\n' "$CHANGED" | grep -Evq '^(lib/omniauth-v2-ynab/version\.rb|\.github/workflows/release\.yml|\.github/tests/release_contract\.py)$'; then
|
|
57
|
+
echo "release=true" >> "$GITHUB_OUTPUT"
|
|
58
|
+
else
|
|
59
|
+
echo "release=false" >> "$GITHUB_OUTPUT"
|
|
60
|
+
fi
|
|
61
|
+
|
|
44
62
|
- name: Resolve version
|
|
45
63
|
id: version
|
|
64
|
+
if: steps.changes.outputs.release == 'true'
|
|
65
|
+
env:
|
|
66
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
46
67
|
run: |
|
|
47
68
|
CURRENT=$(ruby -e "require_relative 'lib/omniauth-v2-ynab/version'; puts OmniAuth::YNAB::VERSION")
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
# Fail closed on registry errors; parse JSON rather than depending on spacing.
|
|
70
|
+
VERSIONS=$(curl --fail --silent --show-error "https://rubygems.org/api/v1/versions/omniauth-v2-ynab.json")
|
|
71
|
+
PUBLISHED=$(printf '%s' "$VERSIONS" | ruby -rjson -e 'puts JSON.parse(STDIN.read).map { |v| v.fetch("number") }')
|
|
72
|
+
released() {
|
|
73
|
+
git rev-parse --verify "refs/tags/v$1" >/dev/null 2>&1 ||
|
|
74
|
+
printf '%s\n' "$PUBLISHED" | grep -Fxq "$1"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
VERSION="$CURRENT"
|
|
78
|
+
BUMPED=false
|
|
79
|
+
if released "$CURRENT"; then
|
|
55
80
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
|
|
56
|
-
|
|
57
|
-
sed -i "s/VERSION = \"$CURRENT\".freeze/VERSION = \"$
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
echo "
|
|
63
|
-
|
|
64
|
-
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
|
81
|
+
VERSION="$MAJOR.$((MINOR + 1)).0"
|
|
82
|
+
sed -i "s/VERSION = \"$CURRENT\".freeze/VERSION = \"$VERSION\".freeze/" lib/omniauth-v2-ynab/version.rb
|
|
83
|
+
BUMPED=true
|
|
84
|
+
fi
|
|
85
|
+
PUBLISH=true
|
|
86
|
+
if released "$VERSION"; then
|
|
87
|
+
echo "v$VERSION already exists; skipping publication, tags and release creation"
|
|
88
|
+
PUBLISH=false
|
|
65
89
|
fi
|
|
90
|
+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
91
|
+
echo "bumped=$BUMPED" >> "$GITHUB_OUTPUT"
|
|
92
|
+
echo "publish=$PUBLISH" >> "$GITHUB_OUTPUT"
|
|
66
93
|
|
|
67
94
|
- name: Build gem
|
|
95
|
+
if: steps.version.outputs.publish == 'true'
|
|
68
96
|
run: gem build omniauth-v2-ynab.gemspec
|
|
69
97
|
|
|
70
98
|
- name: Configure RubyGems credentials (OIDC)
|
|
99
|
+
if: steps.version.outputs.publish == 'true'
|
|
71
100
|
uses: rubygems/configure-rubygems-credentials@main
|
|
72
101
|
|
|
73
102
|
- name: Push to RubyGems
|
|
103
|
+
if: steps.version.outputs.publish == 'true'
|
|
74
104
|
run: gem push omniauth-v2-ynab-*.gem
|
|
75
105
|
|
|
76
106
|
- name: Tag release
|
|
107
|
+
if: steps.version.outputs.publish == 'true'
|
|
77
108
|
run: |
|
|
78
109
|
git tag "v${{ steps.version.outputs.version }}"
|
|
79
110
|
git push origin "v${{ steps.version.outputs.version }}"
|
|
80
111
|
|
|
81
112
|
- name: Create GitHub Release
|
|
113
|
+
if: steps.version.outputs.publish == 'true'
|
|
82
114
|
env:
|
|
83
115
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
84
116
|
run: |
|
|
@@ -87,9 +119,31 @@ jobs:
|
|
|
87
119
|
--title "v${{ steps.version.outputs.version }}" \
|
|
88
120
|
--generate-notes
|
|
89
121
|
|
|
90
|
-
- name:
|
|
122
|
+
- name: Propose version bookkeeping PR
|
|
91
123
|
if: steps.version.outputs.bumped == 'true'
|
|
124
|
+
env:
|
|
125
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
126
|
+
VERSION: ${{ steps.version.outputs.version }}
|
|
92
127
|
run: |
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
git
|
|
128
|
+
BRANCH="release/bookkeeping-v$VERSION"
|
|
129
|
+
# Never overwrite a branch belonging to another writer.
|
|
130
|
+
git fetch origin
|
|
131
|
+
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null; then
|
|
132
|
+
git fetch origin "$BRANCH"
|
|
133
|
+
git diff --exit-code FETCH_HEAD
|
|
134
|
+
else
|
|
135
|
+
git switch -c "$BRANCH"
|
|
136
|
+
git add lib/omniauth-v2-ynab/version.rb
|
|
137
|
+
git commit -m "[auto] Bump version to $VERSION"
|
|
138
|
+
git push origin "HEAD:refs/heads/$BRANCH"
|
|
139
|
+
fi
|
|
140
|
+
echo "Ready bookkeeping branch: $BRANCH" >> "$GITHUB_STEP_SUMMARY"
|
|
141
|
+
PR=$(gh pr list --head "$BRANCH" --base main --state all --json url --jq '.[0].url')
|
|
142
|
+
if [ -n "$PR" ]; then
|
|
143
|
+
echo "$PR" >> "$GITHUB_STEP_SUMMARY"
|
|
144
|
+
elif ! gh pr create --head "$BRANCH" --base main \
|
|
145
|
+
--title "[auto] Bump version to $VERSION" \
|
|
146
|
+
--body "Record the already published v$VERSION. This bookkeeping-only merge does not publish a gem."; then
|
|
147
|
+
echo "::error::Bookkeeping branch is ready, but GITHUB_TOKEN cannot create its PR. Check the reported API error and repository policy, or have a maintainer open the PR; do not rerun publication."
|
|
148
|
+
exit 1
|
|
149
|
+
fi
|
data/Gemfile
CHANGED
|
@@ -147,6 +147,7 @@ module OmniAuth
|
|
|
147
147
|
|
|
148
148
|
# Constant-time comparison to prevent timing attacks on state parameter.
|
|
149
149
|
def secure_compare(string_a, string_b)
|
|
150
|
+
return false unless string_a.is_a?(String) && string_b.is_a?(String)
|
|
150
151
|
return false unless string_a.bytesize == string_b.bytesize
|
|
151
152
|
|
|
152
153
|
l = string_a.unpack("C#{string_a.bytesize}")
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
require "rack/mock"
|
|
3
|
+
require "webmock/rspec"
|
|
4
|
+
require "action_controller"
|
|
5
|
+
require "omniauth/rails_csrf_protection/token_verifier"
|
|
6
|
+
|
|
7
|
+
RSpec.describe "real request validation and OAuth callback with synthetic session/provider" do
|
|
8
|
+
include WebMock::API
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
@prior_config = {:test_mode => OmniAuth.config.test_mode, :allowed_request_methods => OmniAuth.config.allowed_request_methods, :request_validation_phase => OmniAuth.config.request_validation_phase, :on_failure => OmniAuth.config.on_failure}
|
|
12
|
+
@prior_forgery = ActionController::Base.allow_forgery_protection
|
|
13
|
+
@prior_origin = ActionController::Base.forgery_protection_origin_check
|
|
14
|
+
WebMock.disable_net_connect!
|
|
15
|
+
OmniAuth.config.test_mode = false
|
|
16
|
+
OmniAuth.config.allowed_request_methods = [:post]
|
|
17
|
+
ActionController::Base.allow_forgery_protection = true
|
|
18
|
+
ActionController::Base.forgery_protection_origin_check = true
|
|
19
|
+
OmniAuth.config.request_validation_phase = OmniAuth::RailsCsrfProtection::TokenVerifier.new
|
|
20
|
+
OmniAuth.config.on_failure = ->(env) { [403, {"content-type" => "text/plain"}, [env["omniauth.error.type"].to_s]] }
|
|
21
|
+
@session = {}
|
|
22
|
+
@app = OmniAuth::Strategies::YNAB.new(->(env) { [200, {"content-type" => "text/plain"}, [env["omniauth.auth"] ? env["omniauth.auth"].credentials.token : "passthrough"]] }, "synthetic-client", "synthetic-secret", :client_options => {:site => "https://synthetic-provider.example.invalid", :token_url => "/oauth/token", :authorize_url => "/oauth/authorize"})
|
|
23
|
+
controller = ActionController::Base.new
|
|
24
|
+
token_env = Rack::MockRequest.env_for("http://example.org/form")
|
|
25
|
+
token_env["rack.session"] = @session
|
|
26
|
+
controller.set_request!(ActionDispatch::Request.new(token_env))
|
|
27
|
+
@token = controller.send(:form_authenticity_token)
|
|
28
|
+
controller.send(:commit_csrf_token, controller.request)
|
|
29
|
+
end
|
|
30
|
+
after do
|
|
31
|
+
@prior_config.each { |key, value| OmniAuth.config.public_send("#{key}=", value) }
|
|
32
|
+
ActionController::Base.allow_forgery_protection = @prior_forgery
|
|
33
|
+
ActionController::Base.forgery_protection_origin_check = @prior_origin
|
|
34
|
+
end
|
|
35
|
+
def request(path, method: "GET", params: {}, session: @session)
|
|
36
|
+
env = Rack::MockRequest.env_for("http://example.org#{path}", :method => method, :params => params)
|
|
37
|
+
env["rack.session"] = session
|
|
38
|
+
env["HTTP_ORIGIN"] = @origin if @origin
|
|
39
|
+
@app.call(env)
|
|
40
|
+
end
|
|
41
|
+
it "accepts authentic POST, issues state, exchanges code, and delivers auth token" do
|
|
42
|
+
status, headers, = request("/auth/ynab", :method => "POST", :params => {:authenticity_token => @token})
|
|
43
|
+
expect(status).to eq(302)
|
|
44
|
+
expect(headers["location"]).to start_with("https://synthetic-provider.example.invalid/oauth/authorize")
|
|
45
|
+
state = @session.fetch("omniauth.state")
|
|
46
|
+
expect(state).to match(/\A[0-9a-f]{48}\z/)
|
|
47
|
+
stub_request(:post, "https://synthetic-provider.example.invalid/oauth/token").with(:body => hash_including("code" => "synthetic-code", "grant_type" => "authorization_code")).to_return(:status => 200, :headers => {"Content-Type" => "application/json"}, :body => '{"access_token":"synthetic-token","token_type":"Bearer","expires_in":3600}')
|
|
48
|
+
status, _, body = request("/auth/ynab/callback", :params => {:code => "synthetic-code", :state => state})
|
|
49
|
+
expect(status).to eq(200)
|
|
50
|
+
expect(body).to eq(["synthetic-token"])
|
|
51
|
+
expect(@session).not_to have_key("omniauth.state")
|
|
52
|
+
status, _, body = request("/auth/ynab/callback", :params => {:code => "synthetic-code", :state => state})
|
|
53
|
+
expect(status).to eq(403)
|
|
54
|
+
expect(body).to eq(["csrf_detected"])
|
|
55
|
+
expect(a_request(:post, "https://synthetic-provider.example.invalid/oauth/token")).to have_been_made.once
|
|
56
|
+
end
|
|
57
|
+
it "rejects missing, invalid and another-session CSRF tokens before redirect" do
|
|
58
|
+
[nil, "invalid", @token].each_with_index do |token, i|
|
|
59
|
+
status, _, body = request("/auth/ynab", :method => "POST", :params => token ? {:authenticity_token => token} : {}, :session => i == 2 ? {} : @session)
|
|
60
|
+
expect(status).to eq(403)
|
|
61
|
+
expect(body).to eq(["ActionController::InvalidAuthenticityToken"])
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
it "rejects cross-origin authentic POST and disallows GET initiation" do
|
|
65
|
+
@origin = "https://attacker.example.invalid"
|
|
66
|
+
status, _, body = request("/auth/ynab", :method => "POST", :params => {:authenticity_token => @token})
|
|
67
|
+
expect(status).to eq(403)
|
|
68
|
+
expect(body).to eq(["ActionController::InvalidAuthenticityToken"])
|
|
69
|
+
status, _, body = request("/auth/ynab")
|
|
70
|
+
expect(status).to eq(200)
|
|
71
|
+
expect(body).to eq(["passthrough"])
|
|
72
|
+
end
|
|
73
|
+
it "rejects missing, mismatched and another-session OAuth state without token exchange" do
|
|
74
|
+
request("/auth/ynab", :method => "POST", :params => {:authenticity_token => @token})
|
|
75
|
+
state = @session.fetch("omniauth.state")
|
|
76
|
+
[[{}, @session], [{:state => "wrong"}, @session], [{:state => state}, {}]].each do |params, session|
|
|
77
|
+
status, _, body = request("/auth/ynab/callback", :params => params.merge(:code => "synthetic-code"), :session => session)
|
|
78
|
+
expect(status).to eq(403)
|
|
79
|
+
expect(body).to eq(["csrf_detected"])
|
|
80
|
+
end
|
|
81
|
+
expect(a_request(:post, "https://synthetic-provider.example.invalid/oauth/token")).not_to have_been_made
|
|
82
|
+
end
|
|
83
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth-v2-ynab
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tataihono
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oauth2
|
|
@@ -45,6 +45,7 @@ executables: []
|
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
|
+
- ".github/tests/release_contract.py"
|
|
48
49
|
- ".github/workflows/ci.yml"
|
|
49
50
|
- ".github/workflows/release.yml"
|
|
50
51
|
- ".rspec"
|
|
@@ -60,6 +61,7 @@ files:
|
|
|
60
61
|
- omniauth-v2-ynab.gemspec
|
|
61
62
|
- renovate.json
|
|
62
63
|
- spec/helper.rb
|
|
64
|
+
- spec/omniauth/strategies/ynab_csrf_spec.rb
|
|
63
65
|
- spec/omniauth/strategies/ynab_spec.rb
|
|
64
66
|
homepage: https://github.com/tataihono/omniauth-v2-ynab
|
|
65
67
|
licenses:
|