-
Notifications
You must be signed in to change notification settings - Fork 122
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
Reject invalid mirroring URI #1012
Conversation
Motivation: An expected remote URI for mirroring is `<domain.com>/<org>/<repo>.git`. However, both the mirror UI and REST API didn't validate the input. For example, a SSH URL, `github.com:line/centraldogma.git` is not valid in Central Dogma but can be committed. Exceptions are raised later when it is used. Additionally, I also fixed a bug where settings tabs are not visible to admin that I found while fixing this bug. Modifications: - Improved the regular expression for `remoteUri` to strictly check the input. - Validate a remote URI in the mirror REST API. - Always set the project role of adminstrator to `OWNER` Result: Invalid remote URIs are now rejected by the mirror UI and API.
@@ -99,6 +100,11 @@ public MirrorConfig(@JsonProperty("id") String id, | |||
this.localRepo = requireNonNull(localRepo, "localRepo"); | |||
this.localPath = firstNonNull(localPath, "/"); | |||
this.remoteUri = requireNonNull(remoteUri, "remoteUri"); | |||
|
|||
// Validate the remote URI. | |||
final String suffix = remoteUri.getScheme().equals(SCHEME_DOGMA) ? "dogma" : "git"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we do this in the MirrorDto
or MirroringServiceV1
?
How about also checking if the local repo exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we do this in the MirrorDto or MirroringServiceV1?
I chose this place because the segments of remote URI in MirrorDto
need to be assembled.
Lines 301 to 306 in 5fec9f1
private static MirrorConfig converterToMirrorConfig(MirrorDto mirrorDto) { | |
final String remoteUri = | |
mirrorDto.remoteScheme() + "://" + mirrorDto.remoteUrl() + | |
MirrorUtil.normalizePath(mirrorDto.remotePath()) + '#' + mirrorDto.remoteBranch(); | |
return new MirrorConfig( |
How about also checking if the local repo exists?
That would be covered by Mirror UI which provides a select box to list local repos.
However, validation on the server side is a also good idea. I will do it in the f/u work. 😉
How about trying mirroring before pushing so that an invalid configuration isn't committed at all? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍
This PR focuses on validating a remote URI. I will do it in the next milestone while implementing #700 |
Motivation:
An expected remote URI for mirroring is
<domain.com>/<org>/<repo>.git
. However, both the mirror UI and REST API didn't validate the input.For example, a SSH URL,
github.com:line/centraldogma.git
is not valid in Central Dogma but can be committed. Exceptions are raised later when it is used.Additionally, I also fixed a bug where settings tabs are not visible to admin that I found while fixing this bug.
Modifications:
remoteUri
to strictly check the input.OWNER
Result:
Invalid remote URIs are now rejected by the mirror UI and API.