Skip to content

Commit

Permalink
Merge branch 'main' into exp/migration
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek authored Nov 29, 2024
2 parents a306f64 + 0aabebc commit 6a109d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
17 changes: 8 additions & 9 deletions components/server/src/bitbucket/bitbucket-repository-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ export class BitbucketRepositoryProvider implements RepositoryProvider {

async hasReadAccess(user: User, owner: string, repo: string): Promise<boolean> {
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(
Expand Down
15 changes: 13 additions & 2 deletions test/tests/components/ws-manager/dotfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand All @@ -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())),
},
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 6a109d3

Please sign in to comment.