From 050942fe05727e157283fbb2f4c7630e396b4d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Fri, 29 Nov 2024 09:39:06 +0100 Subject: [PATCH 1/2] Don't be so chatty when `hasReadAccess` throws (#20400) --- .../bitbucket/bitbucket-repository-provider.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/components/server/src/bitbucket/bitbucket-repository-provider.ts b/components/server/src/bitbucket/bitbucket-repository-provider.ts index 8be1cc5bc9bbd0..9538645642bf27 100644 --- a/components/server/src/bitbucket/bitbucket-repository-provider.ts +++ b/components/server/src/bitbucket/bitbucket-repository-provider.ts @@ -123,15 +123,14 @@ export class BitbucketRepositoryProvider implements RepositoryProvider { async hasReadAccess(user: User, owner: string, repo: string): Promise { const api = await this.apiFactory.create(user); - try { - await api.repositories.get({ workspace: owner, repo_slug: repo }); - // we assume that if the current token is good to read the repository details, - // then the repository is accessible - return true; - } catch (err) { - console.warn({ userId: user.id }, "hasReadAccess error", err, { owner, repo }); - return false; - } + const result = await api.repositories.get({ workspace: owner, repo_slug: repo }).catch((e) => { + console.warn({ userId: user.id }, "hasReadAccess error", { owner, repo, status: e.status }); + return null; + }); + + // we assume that if the current token is good to read the repository details, + // then the repository is accessible + return result !== null; } public async getCommitHistory( From 0aabebcf903d430f978349774e48a1302f2a067d Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 29 Nov 2024 18:36:06 +0800 Subject: [PATCH 2/2] [tests] show dotfile installing failure reason (#20397) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [tests] show dotfile installing failure reason * Fix dotfile tests * Add docs --------- Co-authored-by: Filip Troníček --- test/tests/components/ws-manager/dotfiles_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/tests/components/ws-manager/dotfiles_test.go b/test/tests/components/ws-manager/dotfiles_test.go index 592499f6f963f1..0e4b5c8a6acce6 100644 --- a/test/tests/components/ws-manager/dotfiles_test.go +++ b/test/tests/components/ws-manager/dotfiles_test.go @@ -45,12 +45,14 @@ func TestDotfiles(t *testing.T) { t.Fatal(err) } + // Scopes should larger than https://github.com/gitpod-io/gitpod/blob/main/components/supervisor/pkg/serverapi/publicapi.go#L99-L109 tokenId, err := api.CreateOAuth2Token(username, []string{ "function:getToken", "function:openPort", "function:getOpenPorts", "function:guessGitTokenScopes", "function:getWorkspace", + "function:sendHeartBeat", "function:trackEvent", "resource:token::*::get", }) @@ -70,8 +72,8 @@ func TestDotfiles(t *testing.T) { "token": "%v", "kind": "gitpod", "host": "%v", - "scope": ["function:getToken", "function:openPort", "function:getOpenPorts", "function:guessGitTokenScopes", "function:getWorkspace", "function:trackEvent", "resource:token::*::get"], - "expiryDate": "2022-10-26T10:38:05.232Z", + "scope": ["function:getToken", "function:openPort", "function:sendHeartBeat", "function:getOpenPorts", "function:guessGitTokenScopes", "function:getWorkspace", "function:trackEvent", "resource:token::*::get"], + "expiryDate": "2026-10-26T10:38:05.232Z", "reuse": 4 }]`, tokenId, getHostUrl(ctx, t, cfg.Client(), cfg.Namespace())), }, @@ -174,6 +176,15 @@ func assertDotfiles(t *testing.T, rsa *integration.RpcClient) error { } if len(dotfiles) > 0 { + var cat agent.ExecResponse + err := rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ + Dir: "/", + Command: "cat", + Args: []string{"/home/gitpod/.dotfiles.log"}, + }, &cat) + if err == nil { + t.Fatalf("dotfiles were not installed successfully: %+v, .dotfiles.log: %s", dotfiles, cat.Stdout) + } t.Fatalf("dotfiles were not installed successfully: %+v", dotfiles) }