Skip to content

Commit 4d18b22

Browse files
davewalterrizwanreza
authored andcommitted
Fix a bug in the GitHub release source
GetGithubReleaseWithTag will now return ErrNotFound if the repository owner from the GitHubRepository value in the Kilnfile release entry does not match the configured Org.
1 parent c611bfd commit 4d18b22

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

internal/commands/update_release.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func (u UpdateRelease) Execute(args []string) error {
8989
newSHA1 = remoteRelease.SHA1
9090
newSourceID = remoteRelease.RemoteSource
9191
newRemotePath = remoteRelease.RemotePath
92-
9392
} else {
9493
remoteRelease, err = releaseSource.GetMatchedRelease(cargo.BOSHReleaseTarballSpecification{
9594
Name: u.Options.Name,

internal/component/github_release_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ func (grs *GithubReleaseSource) GetGithubReleaseWithTag(ctx context.Context, s c
109109
return nil, ErrNotFound
110110
}
111111

112+
if repoOwner != grs.Org {
113+
grs.Logger.Printf("GitHubRepository owner %q does not match configured Org %q, skipping...", repoOwner, grs.Org)
114+
return nil, ErrNotFound
115+
}
116+
112117
release, response, err := grs.GetReleaseByTag(ctx, repoOwner, repoName, "v"+s.Version)
113118
if err == nil {
114119
err = checkStatus(http.StatusOK, response.StatusCode)

internal/component/github_release_source_test.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,54 @@ func TestGithubReleaseSource_GetMatchedRelease(t *testing.T) {
318318
})
319319
}
320320

321-
func TestGetGithubReleaseWithTag(t *testing.T) {
322-
t.Run("when get release with tag api request fails", func(t *testing.T) {
321+
func TestGithubReleaseSource_GetGithubReleaseWithTag(t *testing.T) {
322+
t.Run("when RepositoryOwnerAndNameFromPath fails", func(t *testing.T) {
323+
damnIt := NewWithT(t)
324+
325+
ctx := context.TODO()
326+
327+
grsMock := &component.GithubReleaseSource{
328+
Logger: log.New(GinkgoWriter, "[test] ", log.Default().Flags()),
329+
ReleaseSourceConfig: cargo.ReleaseSourceConfig{
330+
Type: component.ReleaseSourceTypeGithub,
331+
Org: "cloudfoundry",
332+
GithubToken: "fake-token",
333+
},
334+
}
335+
s := cargo.BOSHReleaseTarballSpecification{
336+
Name: "routing",
337+
Version: "0.226.0",
338+
GitHubRepository: "invalid-uri",
339+
}
340+
341+
_, err := grsMock.GetGithubReleaseWithTag(ctx, s)
342+
damnIt.Expect(err).To(MatchError(component.ErrNotFound))
343+
})
344+
345+
t.Run("when the GitHubRepository owner does not match the configured Org", func(t *testing.T) {
346+
damnIt := NewWithT(t)
347+
348+
ctx := context.TODO()
349+
350+
grsMock := &component.GithubReleaseSource{
351+
Logger: log.New(GinkgoWriter, "[test] ", log.Default().Flags()),
352+
ReleaseSourceConfig: cargo.ReleaseSourceConfig{
353+
Type: component.ReleaseSourceTypeGithub,
354+
Org: "cloudnotfoundry",
355+
GithubToken: "fake-token",
356+
},
357+
}
358+
s := cargo.BOSHReleaseTarballSpecification{
359+
Name: "routing",
360+
Version: "0.226.0",
361+
GitHubRepository: "https://github.com/cloudfoundry/routing-release",
362+
}
363+
364+
_, err := grsMock.GetGithubReleaseWithTag(ctx, s)
365+
damnIt.Expect(err).To(MatchError(component.ErrNotFound))
366+
})
367+
368+
t.Run("when GetReleaseByTag fails", func(t *testing.T) {
323369
damnIt := NewWithT(t)
324370

325371
releaseGetter := new(fakes.ReleaseByTagGetter)

0 commit comments

Comments
 (0)