Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-64803] Fix tags retrieval with folder scoped credentials #1139

Merged
merged 16 commits into from Oct 22, 2021

Conversation

Dohbedoh
Copy link
Contributor

@Dohbedoh Dohbedoh commented Sep 9, 2021

JENKINS-64803 - Test folder scoped credentials

In the context of Shared Library, the fetching of tags fails because the implementation of SCMRevision retrieve​(@NonNull String thingName, @NonNull TaskListener listener, @CheckForNull Item context) eventually loses the Item context. In such cases, the credentials lookup uses getOwner() that in the case of a pipeline library is null. Therefore if the credentials provided are defined at a folder level, the lookup does not find them.

The suggested fix pass the retrieveContext passed from the SCM API does the doRetrieve methods when we have it.

Checklist

  • I have read the CONTRIBUTING doc
  • I have referenced the Jira issue related to my changes in one or more commit messages
  • I have added tests that verify my changes
  • Unit tests pass locally with my changes
  • No Javadoc warnings were introduced with my changes
  • No spotbugs warnings were introduced with my changes
  • I have interactively tested my changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

@Dohbedoh
Copy link
Contributor Author

Dohbedoh commented Sep 9, 2021

First commit showcase the failure. Will commit the fix then to confirm that it fixes it.

@Dohbedoh Dohbedoh marked this pull request as draft September 9, 2021 04:44
@Dohbedoh Dohbedoh marked this pull request as ready for review September 9, 2021 06:40
pom.xml Outdated
@@ -156,6 +156,16 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for contributing tests that show the issue and a fix for the issue.

Based on the comment from @timja in jenkinsci/jenkins#5736 (powermock does not seem to work with Java 17 and has much less frequent releases than mockito), would you consider switching to use the mockito framework that is already used in the git plugin, rather than introducing the powermock framework?

I'm not skilled in mocking. I already struggle to benefit from the mockito based tests and fear that adding another framework will make it more difficult to maintain the plugin.

I removed the powermock framework from the plugin in 2019 with a56d37e It was used by only one test and was making JDK 11 work more difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I think I am able to make it work with just Mockito. But I need to bring in mockito-inline.

SCMRevision rev = source.fetch("lightweight", listener, p);
assertThat(rev, notNullValue());
assertThat(rev.getHead().toString(), equalTo("SCMHead{'lightweight'}"));
Mockito.verify(gitClient, Mockito.times(0)).addDefaultCredentials(null);
Copy link
Member

@timja timja Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would static import mockito and argument matchers as it leads to easier reading of the test imo, also given doReturn is static imported but the rest aren’t…

@Dohbedoh
Copy link
Contributor Author

Dohbedoh commented Oct 5, 2021

Fixed the initialization of TFS tests that seemed to be impacted.

@Dohbedoh
Copy link
Contributor Author

Dohbedoh commented Oct 5, 2021

Hmm.. as soon as a dep on mockito-inline is added, that TFS test fails.

@MarkEWaite MarkEWaite dismissed their stale review October 6, 2021 02:03

Ready to review again

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I need to perform interactive testing before it is merged.

Comment on lines 32 to 36
Collections.singletonList(new UserRemoteConfig(repoUrl, null, null, null)),
new ArrayList<>(),
null, JGitTool.MAGIC_EXENAME,
Collections.<GitSCMExtension>emptyList());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally ask that changes of pure white space not be made because there is a large backlog of closed but potentially useful pull requests that will have merge conflicts if white space is adjusted. Yes, the white space is ugly, but it needs to remain ugly until we have agreement that the source code formatting can be maintained by a program.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright. Let me add a commit to preserve it then.

@MarkEWaite MarkEWaite added the bugfix Fixes a bug - used by Release Drafter label Oct 7, 2021
@Dohbedoh Dohbedoh changed the title [JENKINS-64803] Test case retrieve tags with folder scoped credentials [JENKINS-64803] Fix tags retrieval with folder scoped credentials Oct 8, 2021
Dohbedoh and others added 2 commits October 8, 2021 21:28
@MarkEWaite MarkEWaite merged commit 726274d into jenkinsci:master Oct 22, 2021
@Dohbedoh Dohbedoh deleted the JENKINS-64803 branch October 28, 2021 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes a bug - used by Release Drafter
Projects
None yet
3 participants