Skip to content

Commit

Permalink
Lowercase all stage names
Browse files Browse the repository at this point in the history
This avoids weird situations where someone tries to work around stage
sorting by relying on where lower vs upper case sort, or try to bypass
final or snapshot behavior by using a different case.
  • Loading branch information
ajoberstar committed Jul 4, 2018
1 parent 6d50a3c commit c2a4394
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private Version reckonTargetVersion(VcsInventory inventory, Version targetNormal
String stage = stageCalc.apply(inventory, targetNormal)
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(String::toLowerCase)
.orElse(null);

if (stage != null && !stages.contains(stage)) {
Expand Down Expand Up @@ -191,7 +192,9 @@ public Builder scopeCalc(Function<VcsInventory, Optional<String>> scopeCalc) {
* @return this builder
*/
public Builder stages(String... stages) {
this.stages = Arrays.stream(stages).collect(Collectors.toSet());
this.stages = Arrays.stream(stages)
.map(String::toLowerCase)
.collect(Collectors.toSet());
this.defaultStage = this.stages.stream()
.filter(name -> !FINAL_STAGE.equals(name))
.sorted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ class ReckonerTest extends Specification {
thrown(IllegalArgumentException)
}

@Unroll
def 'stages are lowercased'(String stage) {
given:
VcsInventory inventory = new VcsInventory(
'abcdef',
true,
null,
Version.valueOf('1.2.3-beta.1'),
Version.valueOf('1.2.2'),
1,
[Version.valueOf('1.3.0')] as Set,
[Version.valueOf('2.0.0-rc.1')] as Set
)
when:
Reckoner.builder()
.clock(CLOCK)
.vcs { -> inventory }
.scopeCalc { i -> Optional.empty() }
.stages('beTA', 'miLEStone', 'RC', 'Final')
.stageCalc { i, v -> Optional.ofNullable(stage) }
.build()
.reckon()
then:
notThrown(IllegalArgumentException)
where:
stage << ['BeTa', 'Milestone', 'rc', 'fINal']
}

def 'if version is claimed, throw'() {
given:
VcsInventory inventory = new VcsInventory(
Expand Down

0 comments on commit c2a4394

Please sign in to comment.