Add factories to create a token as a string.
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-12-01 14:04:47 +02:00
parent 23bdfd10cf
commit e99a0bc771
6 changed files with 104 additions and 0 deletions
@@ -0,0 +1,38 @@
package space.kklochko.spring_rest_example.security.tokens
import spock.lang.Specification
import spock.lang.Subject
class SimpleRandomTokenSpec extends Specification {
def "Create a token that based on sha256"() {
given: "I have a token factory"
@Subject
def factory = new SimpleRandomToken()
and: "I have a input data"
String input = "hello"
when: "I create a token"
String token = factory.create(input)
then: "The token is the same if the same input data."
token.length() == 64
}
def "Token must be different for the same input data"() {
given: "I have a token factory"
@Subject
def factory = new SimpleRandomToken()
and: "I have a input data"
String input = "hello"
when: "I create tokens"
String token = factory.create(input)
String token2 = factory.create(input)
then: "The tokens are different"
token != token2
}
}
@@ -0,0 +1,24 @@
package space.kklochko.spring_rest_example.security.tokens
import spock.lang.Specification
import spock.lang.Subject
class SimpleTokenSpec extends Specification {
def "Create a token that based on sha256"() {
given: "I have a token factory"
@Subject
def factory = new SimpleToken()
when: "I create a token"
String token = factory.create(input)
then: "The token is the same if the same input data."
expectedToken == token
where: "I have the expected data"
input || expectedToken
"abc" || "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
"random numbers232341" || "7f4b80b2b09ae4326f78b1a9782c807af0a7d0194bffb05602a6585466b4c43e"
}
}