fix(sync): la verification 'depot public' se fait sans jeton, avant tout le reste
Un jeton faux faisait repondre 401 a GitHub avant tout verdict : le refus d'un depot public ne pouvait pas s'exprimer. Public = visible en anonyme. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -140,7 +140,8 @@ begin
|
|||||||
LHttp.ResponseTimeout := FTimeoutMs;
|
LHttp.ResponseTimeout := FTimeoutMs;
|
||||||
LHttp.HandleRedirects := False;
|
LHttp.HandleRedirects := False;
|
||||||
LHttp.UserAgent := 'PMServer';
|
LHttp.UserAgent := 'PMServer';
|
||||||
LHttp.CustomHeaders['Authorization'] := 'token ' + FToken;
|
// SANS JETON, expres : "public" = visible par n'importe qui. Un jeton faux
|
||||||
|
// faisait repondre 401 avant tout verdict ; prive et anonyme = 404.
|
||||||
try
|
try
|
||||||
LResp := LHttp.Get(RepoApiUrl(FBaseUrl));
|
LResp := LHttp.Get(RepoApiUrl(FBaseUrl));
|
||||||
except
|
except
|
||||||
|
|||||||
@@ -1659,7 +1659,12 @@ begin
|
|||||||
// "token <PAT>" et non "Bearer" : c'est la forme que Gitea attend
|
// "token <PAT>" et non "Bearer" : c'est la forme que Gitea attend
|
||||||
// d'un jeton d'acces personnel, et l'autre donne un 401 muet.
|
// d'un jeton d'acces personnel, et l'autre donne un 401 muet.
|
||||||
if LGitea then
|
if LGitea then
|
||||||
LHttp.CustomHeaders['Authorization'] := 'token ' + LPwd
|
begin
|
||||||
|
// Pas d'en-tete du tout sans jeton : la verification "depot
|
||||||
|
// public" se fait volontairement en anonyme.
|
||||||
|
if LPwd <> '' then
|
||||||
|
LHttp.CustomHeaders['Authorization'] := 'token ' + LPwd;
|
||||||
|
end
|
||||||
else if (LUser <> '') then
|
else if (LUser <> '') then
|
||||||
begin
|
begin
|
||||||
LHttp.CredentialsStorage.AddCredential(
|
LHttp.CredentialsStorage.AddCredential(
|
||||||
|
|||||||
+8
-3
@@ -115,7 +115,11 @@ function syncNormalizeRepoUrl(u) {
|
|||||||
async function syncRepoPublicWarning(cfg) {
|
async function syncRepoPublicWarning(cfg) {
|
||||||
if (!syncIsGitea(cfg.url)) return '';
|
if (!syncIsGitea(cfg.url)) return '';
|
||||||
const repoUrl = cfg.url.split('/contents/')[0];
|
const repoUrl = cfg.url.split('/contents/')[0];
|
||||||
const r = await _webdavCall('get', repoUrl, cfg.user, cfg.pwd);
|
// SANS JETON, expres : "public" veut dire "visible par n'importe qui", et
|
||||||
|
// c'est exactement la question posee. Avec un jeton faux, GitHub repondait
|
||||||
|
// 401 avant de dire quoi que ce soit du depot ; un depot prive repond 404
|
||||||
|
// sans jeton, ce qui veut dire "pas public".
|
||||||
|
const r = await _webdavCall('get', repoUrl, '', '');
|
||||||
if (r.status < 200 || r.status >= 300 || !r.payload) return '';
|
if (r.status < 200 || r.status >= 300 || !r.payload) return '';
|
||||||
try {
|
try {
|
||||||
const o = JSON.parse(new TextDecoder().decode(base64ToBytes(r.payload)));
|
const o = JSON.parse(new TextDecoder().decode(base64ToBytes(r.payload)));
|
||||||
@@ -309,6 +313,9 @@ async function syncTestConnection() {
|
|||||||
const cfg = await loadSyncConfig(true); // needs the WebDAV credentials
|
const cfg = await loadSyncConfig(true); // needs the WebDAV credentials
|
||||||
if (!cfg || !cfg.url) return toast('Set the WebDAV URL first', 'warning');
|
if (!cfg || !cfg.url) return toast('Set the WebDAV URL first', 'warning');
|
||||||
toast('Testing connection…');
|
toast('Testing connection…');
|
||||||
|
// LE DEPOT PUBLIC D'ABORD : il est refuse quel que soit le jeton.
|
||||||
|
const pubFirst = await syncRepoPublicWarning(cfg);
|
||||||
|
if (pubFirst) return toast(pubFirst, 'error');
|
||||||
const r = await _webdavCall('test', cfg.url, cfg.user, cfg.pwd);
|
const r = await _webdavCall('test', cfg.url, cfg.user, cfg.pwd);
|
||||||
// A reachable Gitea with a valid token is not enough: a URL pointing one
|
// A reachable Gitea with a valid token is not enough: a URL pointing one
|
||||||
// path segment off answers 200 with JSON that is not a file. Checking the
|
// path segment off answers 200 with JSON that is not a file. Checking the
|
||||||
@@ -318,8 +325,6 @@ async function syncTestConnection() {
|
|||||||
try {
|
try {
|
||||||
un = giteaUnwrap(new TextDecoder().decode(base64ToBytes(r.payload || '')));
|
un = giteaUnwrap(new TextDecoder().decode(base64ToBytes(r.payload || '')));
|
||||||
} catch (e) { /* traite comme une forme inattendue */ }
|
} catch (e) { /* traite comme une forme inattendue */ }
|
||||||
const pub = await syncRepoPublicWarning(cfg);
|
|
||||||
if (pub) return toast(pub, 'error');
|
|
||||||
return un
|
return un
|
||||||
? toast('Connection OK · file found in the repository')
|
? toast('Connection OK · file found in the repository')
|
||||||
: toast('Reached Gitea, but this URL does not return a file — ' +
|
: toast('Reached Gitea, but this URL does not return a file — ' +
|
||||||
|
|||||||
Reference in New Issue
Block a user