-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Options for setting the expiration date when signing
Signed-off-by: Jochen Schneider <[email protected]>
- Loading branch information
Jochen Schneider
committed
Aug 12, 2019
1 parent
89ec974
commit 3ddddbd
Showing
10 changed files
with
163 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
cli/src/test/scala/com/advancedtelematic/tuf/cli/CommandHandlerExpirationDateSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.advancedtelematic.tuf.cli | ||
|
||
import java.time.{Instant, Period} | ||
|
||
import com.advancedtelematic.tuf.cli.Errors.PastDate | ||
import org.scalatest.{FunSuite, Matchers} | ||
|
||
class CommandHandlerExpirationDateSpec extends FunSuite with Matchers { | ||
val now = Instant.EPOCH | ||
val oneDay = Period.ofDays(1) | ||
val inADay = now.plus(oneDay) | ||
val aDayAgo = now.minus(oneDay) | ||
|
||
// the actual command doesn't matter | ||
private val cmd = Commands.SignRoot | ||
|
||
test("expirationDate from previous value") { | ||
val d = CommandHandler.expirationDate(Config(cmd), now)(inADay) | ||
d shouldBe inADay | ||
} | ||
|
||
test("expirationDate from previous value in the past") { | ||
intercept[PastDate] { | ||
CommandHandler.expirationDate(Config(cmd), now)(aDayAgo) | ||
} | ||
} | ||
|
||
test("expirationDate from expireOn") { | ||
val d = CommandHandler.expirationDate(Config(cmd, expireOn = Some(inADay)), now)(aDayAgo) | ||
d shouldBe inADay | ||
} | ||
|
||
test("expirationDate from expireOn in the past") { | ||
intercept[PastDate] { | ||
CommandHandler.expirationDate(Config(cmd, expireOn = Some(now.minusSeconds(1))), now)(aDayAgo) | ||
} | ||
} | ||
|
||
test("expirationDate from expireOn in the past, but forced") { | ||
val d = CommandHandler.expirationDate(Config(cmd, force = true, expireOn = Some(now.minusSeconds(1))), now)(aDayAgo) | ||
d shouldBe now.minusSeconds(1) | ||
} | ||
|
||
test("expirationDate from expireAfter") { | ||
val d = CommandHandler.expirationDate(Config(cmd, expireAfter = Some(oneDay)), now)(aDayAgo) | ||
d shouldBe inADay | ||
} | ||
|
||
test("expirationDate from expireAfter in the past") { | ||
intercept[PastDate] { | ||
CommandHandler.expirationDate(Config(cmd, expireAfter = Some(Period.ofDays(-1))), now)(aDayAgo) | ||
} | ||
} | ||
|
||
test("expirationDate from expireAfter in the past, but forced") { | ||
val d = CommandHandler.expirationDate(Config(cmd, force = true, expireAfter = Some(Period.ofDays(-1))), now)(aDayAgo) | ||
d shouldBe now.minus(oneDay) | ||
} | ||
|
||
} |
Oops, something went wrong.