Skip to content

Commit 9b487c7

Browse files
committed
Add tests for credential and property preservation
Verify that credentials, authentication blocks, and other repository properties (name, allowInsecureProtocol) are preserved when changing URLs within the same repository type.
1 parent 8b79abb commit 9b487c7

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeRepositoryTest.java

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,132 @@ void matchByUrlOnlyReplace() {
371371
);
372372
}
373373

374+
@Test
375+
void preservesCredentialsWhenChangingUrl() {
376+
rewriteRun(
377+
spec -> spec.recipe(new ChangeRepository("maven", "https://old-nexus.example.com/releases", "maven", "https://new-nexus.example.com/releases")),
378+
buildGradle(
379+
"""
380+
repositories {
381+
maven {
382+
url = "https://old-nexus.example.com/releases"
383+
credentials {
384+
username = findProperty("mavenUsername")
385+
password = findProperty("mavenPassword")
386+
}
387+
}
388+
}
389+
""",
390+
"""
391+
repositories {
392+
maven {
393+
url = "https://new-nexus.example.com/releases"
394+
credentials {
395+
username = findProperty("mavenUsername")
396+
password = findProperty("mavenPassword")
397+
}
398+
}
399+
}
400+
"""
401+
)
402+
);
403+
}
404+
405+
@Test
406+
void preservesCredentialsWhenChangingUrlKts() {
407+
rewriteRun(
408+
spec -> spec.recipe(new ChangeRepository("maven", "https://old-nexus.example.com/releases", "maven", "https://new-nexus.example.com/releases")),
409+
buildGradleKts(
410+
"""
411+
repositories {
412+
maven {
413+
url = uri("https://old-nexus.example.com/releases")
414+
credentials {
415+
username = System.getenv("MAVEN_USERNAME")
416+
password = System.getenv("MAVEN_PASSWORD")
417+
}
418+
}
419+
}
420+
""",
421+
"""
422+
repositories {
423+
maven {
424+
url = uri("https://new-nexus.example.com/releases")
425+
credentials {
426+
username = System.getenv("MAVEN_USERNAME")
427+
password = System.getenv("MAVEN_PASSWORD")
428+
}
429+
}
430+
}
431+
"""
432+
)
433+
);
434+
}
435+
436+
@Test
437+
void preservesAuthenticationBlockWhenChangingUrl() {
438+
rewriteRun(
439+
spec -> spec.recipe(new ChangeRepository("maven", "https://old-nexus.example.com/releases", "maven", "https://new-nexus.example.com/releases")),
440+
buildGradle(
441+
"""
442+
repositories {
443+
maven {
444+
url = "https://old-nexus.example.com/releases"
445+
credentials {
446+
username = findProperty("mavenUsername")
447+
password = findProperty("mavenPassword")
448+
}
449+
authentication {
450+
basic(BasicAuthentication)
451+
}
452+
}
453+
}
454+
""",
455+
"""
456+
repositories {
457+
maven {
458+
url = "https://new-nexus.example.com/releases"
459+
credentials {
460+
username = findProperty("mavenUsername")
461+
password = findProperty("mavenPassword")
462+
}
463+
authentication {
464+
basic(BasicAuthentication)
465+
}
466+
}
467+
}
468+
"""
469+
)
470+
);
471+
}
472+
473+
@Test
474+
void preservesNameAndOtherPropertiesWhenChangingUrl() {
475+
rewriteRun(
476+
spec -> spec.recipe(new ChangeRepository("maven", "https://old-nexus.example.com/releases", "maven", "https://new-nexus.example.com/releases")),
477+
buildGradle(
478+
"""
479+
repositories {
480+
maven {
481+
name = "myRepo"
482+
url = "https://old-nexus.example.com/releases"
483+
allowInsecureProtocol = true
484+
}
485+
}
486+
""",
487+
"""
488+
repositories {
489+
maven {
490+
name = "myRepo"
491+
url = "https://new-nexus.example.com/releases"
492+
allowInsecureProtocol = true
493+
}
494+
}
495+
"""
496+
)
497+
);
498+
}
499+
374500
@Test
375501
void removesOldWhenTargetNamedRepoAlreadyExists() {
376502
rewriteRun(

0 commit comments

Comments
 (0)