Skip to content

Commit dce99f4

Browse files
rmmeanstsuyoshizawa
authored andcommitted
Add expiration tests (#112)
* Add tests for verifying logic on checking token expiration. * be more clear on which variables are being set.
1 parent 412f0f2 commit dce99f4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package scalaoauth2.provider
2+
3+
import java.time.{ ZoneOffset, ZonedDateTime }
4+
import java.util.Date
5+
6+
import org.scalatest.Matchers._
7+
import org.scalatest._
8+
9+
class AccessTokenSpec extends FlatSpec {
10+
11+
it should "say a token is active that is not yet expired" in {
12+
val token = AccessToken("token", None, None, lifeSeconds = Some(15), createdAt = new Date())
13+
token.isExpired shouldBe false
14+
}
15+
16+
it should "expire tokens that have a lifespan that has passed" in {
17+
val token = AccessToken("token", None, None, lifeSeconds = Some(1798), createdAt = Date.from(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(1800).toInstant))
18+
token.isExpired shouldBe true
19+
}
20+
21+
it should "not expire tokens that have no lifespan" in {
22+
val token = AccessToken("token", None, None, lifeSeconds = None, createdAt = Date.from(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(1800).toInstant))
23+
token.isExpired shouldBe false
24+
}
25+
}

0 commit comments

Comments
 (0)