How to use digest class of io.kotest.matchers.string package

Best Kotest code snippet using io.kotest.matchers.string.digest

DockerClientLegacyImageBuildSpec.kt

Source:DockerClientLegacyImageBuildSpec.kt Github

copy

Full Screen

...175 it.shouldBeTypeOf<StepPullProgressUpdate>()176 it.stepNumber shouldBe 1177 it.pullProgress.message shouldBe "Pulling from batect/docker-client"178 it.pullProgress.detail shouldBe null179 it.pullProgress.id shouldBeIn setOf(imageReference, imageReference.substringAfter('@')) // Older versions of Docker only return the digest here180 }181 progressUpdatesReceived shouldContain StepPullProgressUpdate(1, ImagePullProgressUpdate("Pulling fs layer", ImagePullProgressDetail(0, 0), layerId))182 // Docker does some rate limiting of progress updates, so to make this test more resilient to this non-determinism, we183 // consider the test passing if at least one of these updates is posted.184 progressUpdatesReceived shouldContainAnyOf setOf(185 StepPullProgressUpdate(1, ImagePullProgressUpdate("Downloading", ImagePullProgressDetail(0, layerSize), layerId)),186 StepPullProgressUpdate(1, ImagePullProgressUpdate("Downloading", ImagePullProgressDetail(layerSize, layerSize), layerId)),187 StepPullProgressUpdate(1, ImagePullProgressUpdate("Download complete", ImagePullProgressDetail(0, 0), layerId))188 )189 progressUpdatesReceived.forAtLeastOne {190 it.shouldBeTypeOf<StepPullProgressUpdate>()191 it.stepNumber shouldBe 1192 it.pullProgress.message shouldBe "Extracting"193 it.pullProgress.detail shouldNotBe null194 it.pullProgress.detail!!.total shouldBe layerSize195 it.pullProgress.id shouldBe layerId196 }197 progressUpdatesReceived shouldEndWith listOf(198 StepPullProgressUpdate(1, ImagePullProgressUpdate("Pull complete", ImagePullProgressDetail(0, 0), layerId)),199 StepPullProgressUpdate(1, ImagePullProgressUpdate("Digest: sha256:a4b51dce3a4b2cc09a2d517c2239b763a84d28e9ab66ce051f2006262f454a24", null, "")),200 StepPullProgressUpdate(1, ImagePullProgressUpdate("Status: Downloaded newer image for $imageReference", null, "")),201 StepOutput(1, "Successfully tagged $imageTag:latest\n"),202 StepFinished(1),203 BuildComplete(image)204 )205 }206 }207 should("be able to build a Linux container image and tag it") {208 val imageTag1 = "batect-docker-client/image-build-test:1"209 val imageTag2 = "batect-docker-client/image-build-test:2"210 client.deleteImageIfPresent(imageTag1)211 client.deleteImageIfPresent(imageTag2)212 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("basic-image"))213 .withLegacyBuilder()214 .withImageTag(imageTag1)215 .withImageTags(setOf(imageTag2))216 .build()217 val output = Buffer()218 client.buildImage(spec, SinkTextOutput(output))219 client.getImage(imageTag1) shouldNotBe null220 client.getImage(imageTag2) shouldNotBe null221 }222 should("be able to reuse a SinkTextOutput instance") {223 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("basic-image"))224 .withLegacyBuilder()225 .withNoBuildCache()226 .build()227 val output = Buffer()228 val sink = SinkTextOutput(output)229 client.buildImage(spec, sink)230 client.buildImage(spec, sink)231 val outputText = output.readUtf8().trim()232 outputText shouldMatch """233 Step 1/2 : FROM alpine:\d+\.\d+.\d+234 ---> [0-9a-f]{12}235 Step 2/2 : RUN echo "Hello world!"236 ---> Running in [0-9a-f]{12}237 Hello world!238 Removing intermediate container [0-9a-f]{12}239 ---> [0-9a-f]{12}240 Successfully built [0-9a-f]{12}241 Step 1/2 : FROM alpine:\d+\.\d+.\d+242 ---> [0-9a-f]{12}243 Step 2/2 : RUN echo "Hello world!"244 ---> Running in [0-9a-f]{12}245 Hello world!246 Removing intermediate container [0-9a-f]{12}247 ---> [0-9a-f]{12}248 Successfully built [0-9a-f]{12}249 """.trimIndent().toRegex()250 }251 should("be able to build a Linux container image that uses a base image that requires authentication") {252 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("authenticated-base-image"))253 .withLegacyBuilder()254 .withBaseImageAlwaysPulled()255 .build()256 val output = Buffer()257 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()258 val image = client.buildImage(spec, SinkTextOutput(output)) { update ->259 progressUpdatesReceived.add(update)260 }261 progressUpdatesReceived shouldEndWith BuildComplete(image)262 }263 should("be able to build a Linux container image where the Dockerfile path is specified with an absolute path") {264 val contextDirectory = rootTestImagesDirectory.resolve("basic-image")265 val spec = ImageBuildSpec.Builder(contextDirectory)266 .withLegacyBuilder()267 .withDockerfile(contextDirectory.resolve("Dockerfile"))268 .build()269 val output = Buffer()270 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()271 val image = client.buildImage(spec, SinkTextOutput(output)) { update ->272 progressUpdatesReceived.add(update)273 }274 progressUpdatesReceived shouldEndWith BuildComplete(image)275 }276 should("be able to build a multi-stage Linux container image") {277 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("multistage"))278 .withLegacyBuilder()279 .build()280 val output = Buffer()281 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()282 val image = client.buildImage(spec, SinkTextOutput(output)) { update ->283 progressUpdatesReceived.add(update)284 }285 val outputText = output.readUtf8().trim()286 outputText shouldContain """^Step 1/4 : FROM alpine:3.14.2 AS other$""".toRegex(RegexOption.MULTILINE)287 outputText shouldContain """^Step 2/4 : RUN touch /file-from-other$""".toRegex(RegexOption.MULTILINE)288 outputText shouldContain """^Step 3/4 : FROM alpine:3.14.2$""".toRegex(RegexOption.MULTILINE)289 outputText shouldContain """^Step 4/4 : COPY --from=other /file-from-other /received/file-from-other$""".toRegex(RegexOption.MULTILINE)290 outputText shouldContain """^Successfully built [0-9a-f]{12}$""".toRegex(RegexOption.MULTILINE)291 progressUpdatesReceived shouldContain StepStarting(1, "FROM alpine:3.14.2 AS other")292 progressUpdatesReceived shouldContain StepStarting(2, "RUN touch /file-from-other")293 progressUpdatesReceived shouldContain StepStarting(3, "FROM alpine:3.14.2")294 progressUpdatesReceived shouldContain StepStarting(4, "COPY --from=other /file-from-other /received/file-from-other")295 progressUpdatesReceived shouldEndWith BuildComplete(image)296 }297 should("be able to build a specific stage of a multi-stage Linux container image") {298 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("multistage-with-failing-default-stage"))299 .withLegacyBuilder()300 .withTargetBuildStage("other")301 .build()302 val output = Buffer()303 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()304 val image = client.buildImage(spec, SinkTextOutput(output)) { update ->305 progressUpdatesReceived.add(update)306 }307 val outputText = output.readUtf8().trim()308 outputText shouldContain """^Step 1/2 : FROM alpine:3.14.2 AS other$""".toRegex(RegexOption.MULTILINE)309 outputText shouldContain """^Step 2/2 : RUN touch /file-from-other$""".toRegex(RegexOption.MULTILINE)310 outputText shouldContain """^Successfully built [0-9a-f]{12}$""".toRegex(RegexOption.MULTILINE)311 progressUpdatesReceived shouldContain StepStarting(1, "FROM alpine:3.14.2 AS other")312 progressUpdatesReceived shouldContain StepStarting(2, "RUN touch /file-from-other")313 progressUpdatesReceived.forNone {314 it.shouldBeTypeOf<StepStarting>()315 it.stepName shouldBe "FROM alpine:3.14.2"316 }317 progressUpdatesReceived shouldEndWith BuildComplete(image)318 }319 should("be able to build a Linux container image with a failing RUN step") {320 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("failing-command"))321 .withLegacyBuilder()322 .build()323 val output = Buffer()324 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()325 val exception = shouldThrow<ImageBuildFailedException> {326 client.buildImage(spec, SinkTextOutput(output)) { update ->327 progressUpdatesReceived.add(update)328 }329 }330 exception.message shouldBe "The command '/bin/sh -c echo \"This command has failed!\" && exit 1' returned a non-zero code: 1"331 val outputText = output.readUtf8().trim()332 outputText shouldContain """^Step 1/2 : FROM alpine:3.14.2$""".toRegex(RegexOption.MULTILINE)333 outputText shouldContain """334 ^Step 2/2 : RUN echo "This command has failed!" && exit 1335 ---> Running in [0-9a-f]{12}336 This command has failed!$337 """.trimIndent().toRegex(RegexOption.MULTILINE)338 outputText shouldNotContain """^Successfully built [0-9a-f]{12}$""".toRegex(RegexOption.MULTILINE)339 progressUpdatesReceived shouldContain StepStarting(1, "FROM alpine:3.14.2")340 progressUpdatesReceived shouldContain StepStarting(2, "RUN echo \"This command has failed!\" && exit 1")341 progressUpdatesReceived shouldContain BuildFailed("The command '/bin/sh -c echo \"This command has failed!\" && exit 1' returned a non-zero code: 1")342 progressUpdatesReceived.forNone {343 it.shouldBeTypeOf<BuildComplete>()344 }345 }346 should("be able to build a Linux container image with a non-existent image") {347 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("failing-base-image"))348 .withLegacyBuilder()349 .build()350 val output = Buffer()351 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()352 val exception = shouldThrow<ImageBuildFailedException> {353 client.buildImage(spec, SinkTextOutput(output)) { update ->354 progressUpdatesReceived.add(update)355 }356 }357 exception.message shouldBeIn setOf(358 "manifest for batect/this-image-does-not-exist:1.0 not found: manifest unknown: manifest unknown",359 "pull access denied for batect/this-image-does-not-exist, repository does not exist or may require 'docker login': denied: requested access to the resource is denied"360 )361 val outputText = output.readUtf8().trim()362 outputText shouldContain """^Step 1/2 : FROM batect/this-image-does-not-exist:1.0$""".toRegex(RegexOption.MULTILINE)363 outputText shouldNotContain """^Successfully built [0-9a-f]{12}$""".toRegex(RegexOption.MULTILINE)364 progressUpdatesReceived shouldContain StepStarting(1, "FROM batect/this-image-does-not-exist:1.0")365 progressUpdatesReceived.shouldContainAnyOf(366 BuildFailed("manifest for batect/this-image-does-not-exist:1.0 not found: manifest unknown: manifest unknown"),367 BuildFailed("pull access denied for batect/this-image-does-not-exist, repository does not exist or may require 'docker login': denied: requested access to the resource is denied"),368 )369 progressUpdatesReceived.forNone {370 it.shouldBeTypeOf<BuildComplete>()371 }372 }373 should("be able to build a Linux container image that downloads a file and report download progress") {374 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("file-download"))375 .withLegacyBuilder()376 .withNoBuildCache()377 .build()378 val output = Buffer()379 val progressUpdatesReceived = mutableListOf<ImageBuildProgressUpdate>()380 val image = client.buildImage(spec, SinkTextOutput(output)) { update ->381 progressUpdatesReceived.add(update)382 }383 val outputText = output.readUtf8().trim()384 outputText shouldMatch """385 Step 1/2 : FROM alpine:3.14.2386 ---> [0-9a-f]{12}387 Step 2/2 : ADD "https://httpbin.org/drip\?duration=1&numbytes=2048&code=200&delay=0" /file.txt\n*388 ---> [0-9a-f]{12}389 Successfully built [0-9a-f]{12}390 """.trimIndent().toRegex()391 progressUpdatesReceived shouldContain StepStarting(1, "FROM alpine:3.14.2")392 progressUpdatesReceived shouldContain StepStarting(2, "ADD \"https://httpbin.org/drip?duration=1&numbytes=2048&code=200&delay=0\" /file.txt")393 progressUpdatesReceived.forAtLeastOne {394 it.shouldBeTypeOf<StepDownloadProgressUpdate>()395 it.stepNumber shouldBe 2396 it.bytesDownloaded shouldBeLessThan 2048397 it.totalBytes shouldBe 2048398 }399 progressUpdatesReceived shouldContain StepDownloadProgressUpdate(2, 2048, 2048)400 progressUpdatesReceived shouldEndWith BuildComplete(image)401 }402 should("gracefully handle a progress callback that throws an exception while building an image") {403 val exceptionThrownByCallbackHandler = RuntimeException("This is an exception from the callback handler")404 val exceptionThrownByBuildMethod = shouldThrow<ImageBuildFailedException> {405 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("basic-image"))406 .withLegacyBuilder()407 .build()408 val output = Buffer()409 client.buildImage(spec, SinkTextOutput(output)) { update ->410 if (update !is ImageBuildContextUploadProgress) {411 throw exceptionThrownByCallbackHandler412 }413 }414 }415 exceptionThrownByBuildMethod.message shouldBe "Image build progress receiver threw an exception: $exceptionThrownByCallbackHandler"416 exceptionThrownByBuildMethod.cause shouldBe exceptionThrownByCallbackHandler417 }418 should("gracefully handle a progress callback that throws an exception while uploading build context") {419 val exceptionThrownByCallbackHandler = RuntimeException("This is an exception from the callback handler")420 val exceptionThrownByBuildMethod = shouldThrow<ImageBuildFailedException> {421 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("basic-image"))422 .withLegacyBuilder()423 .build()424 val output = Buffer()425 client.buildImage(spec, SinkTextOutput(output)) { update ->426 if (update is ImageBuildContextUploadProgress) {427 throw exceptionThrownByCallbackHandler428 }429 }430 }431 exceptionThrownByBuildMethod.message shouldBe "Image build progress receiver threw an exception: $exceptionThrownByCallbackHandler"432 exceptionThrownByBuildMethod.cause shouldBe exceptionThrownByCallbackHandler433 }434 should("propagate configured proxy settings to the build") {435 setClientProxySettingsForTest(client)436 val spec = ImageBuildSpec.Builder(rootTestImagesDirectory.resolve("proxy-reporter"))437 .withLegacyBuilder()438 .withNoBuildCache()439 .build()440 val output = Buffer()441 client.buildImage(spec, SinkTextOutput(output))442 val outputText = output.readUtf8().trim()443 outputText shouldContain "Value of FTP_PROXY is https://ftp-proxy"444 outputText shouldContain "Value of ftp_proxy is https://ftp-proxy"445 outputText shouldContain "Value of HTTPS_PROXY is https://https-proxy"446 outputText shouldContain "Value of https_proxy is https://https-proxy"447 outputText shouldContain "Value of HTTP_PROXY is https://http-proxy"448 outputText shouldContain "Value of http_proxy is https://http-proxy"449 outputText shouldContain "Value of NO_PROXY is https://no-proxy"450 outputText shouldContain "Value of no_proxy is https://no-proxy"451 }452 }453})454internal fun DockerClient.removeBaseImagesIfPresent(dockerfile: Path) {455 val dockerfileContent = readFileContents(dockerfile)456 val fromRegex = """^FROM ([a-zA-Z0-9./_-]+(:[a-zA-Z0-9./_-]+)?(@sha256:[0-9a-f]{64})?)$""".toRegex(RegexOption.MULTILINE)457 fromRegex.findAll(dockerfileContent).forEach { match ->458 val reference = match.groupValues[1]459 deleteImageIfPresent(reference)460 val withoutTag = imageReferenceWithoutTag(reference)461 if (withoutTag != null) {462 deleteImageIfPresent(withoutTag)463 }464 }465}466private fun imageReferenceWithoutTag(imageReference: String): String? {467 val tagStartIndex = imageReference.substringBefore('@').lastIndexOf(':')468 val digestStartIndex = imageReference.lastIndexOf('@')469 if (tagStartIndex == -1 || digestStartIndex == -1) {470 return null471 }472 return imageReference.substring(0, tagStartIndex - 1) + imageReference.substring(digestStartIndex)473}474private fun readFileContents(path: Path): String =475 FileSystem.SYSTEM.read(path) {476 return readUtf8()477 }478internal expect fun setClientProxySettingsForTest(client: DockerClient)...

Full Screen

Full Screen

DockerClientImagePullSpec.kt

Source:DockerClientImagePullSpec.kt Github

copy

Full Screen

...26 val defaultLinuxTestImage = "gcr.io/distroless/static@sha256:aadea1b1f16af043a34491eec481d0132479382096ea34f608087b4bef3634be"27 val defaultWindowsTestImage = "mcr.microsoft.com/windows/nanoserver@sha256:4f06e1d8263b934d2e88dc1c6ff402f5b499c4d19ad6d0e2a5b9ee945f782928" // This is nanoserver:180928 val testImages = when (testEnvironmentContainerOperatingSystem) {29 ContainerOperatingSystem.Linux -> mapOf(30 "with a digest and no tag" to defaultLinuxTestImage,31 "with a digest and tag" to "gcr.io/distroless/static:063a079c1a87bad3369cb9daf05e371e925c0c91@sha256:aadea1b1f16af043a34491eec481d0132479382096ea34f608087b4bef3634be",32 "with a tag and no digest" to "gcr.io/distroless/static:063a079c1a87bad3369cb9daf05e371e925c0c91",33 "with neither a digest nor a tag" to "gcr.io/distroless/static",34 // To recreate this image:35 // docker pull gcr.io/distroless/static@sha256:aadea1b1f16af043a34491eec481d0132479382096ea34f608087b4bef3634be36 // docker tag gcr.io/distroless/static@sha256:aadea1b1f16af043a34491eec481d0132479382096ea34f608087b4bef3634be ghcr.io/batect/docker-client:sample-authenticated-image37 // docker push ghcr.io/batect/docker-client:sample-authenticated-image38 //39 // If you need to configure credentials locally: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry40 "that requires authentication to pull" to "ghcr.io/batect/docker-client:sample-authenticated-image"41 )42 ContainerOperatingSystem.Windows -> mapOf(43 "with a tag" to defaultWindowsTestImage44 )45 }46 val imageThatDoesNotExist = "batect/this-image-does-not-exist:abc123"47 beforeEach {48 testImages.values.forEach { image -> client.deleteImageIfPresent(image) }49 }50 testImages.forEach { (description, image) ->51 should("be able to pull, get and delete an image $description").onlyIfDockerDaemonPresent {52 val imageReferenceFromPull = client.pullImage(image)53 val imageReferenceFromGet = client.getImage(image)54 imageReferenceFromPull shouldBe imageReferenceFromGet55 client.deleteImage(imageReferenceFromPull, force = true)56 val imageReferenceAfterDelete = client.getImage(image)57 imageReferenceAfterDelete shouldBe null58 }59 }60 context("pulling an image that does not exist on the local machine") {61 // Recreate this image with 'resources/base-images/recreate.sh'.62 val image = "ghcr.io/batect/docker-client:image-pull-progress@sha256:ed32e6eb4f059d2ac57e47413855d737db00c21f39edb0a5845c3a30a18a7263"63 val imageWithoutTag = "ghcr.io/batect/docker-client@sha256:ed32e6eb4f059d2ac57e47413855d737db00c21f39edb0a5845c3a30a18a7263"64 beforeAny {65 client.deleteImageIfPresent(image)66 client.deleteImageIfPresent(imageWithoutTag)67 }68 should("report progress information while pulling an image").onlyIfDockerDaemonSupportsLinuxContainers {69 val progressUpdatesReceived = mutableListOf<ImagePullProgressUpdate>()70 client.pullImage(image) { update ->71 progressUpdatesReceived.add(update)72 }73 val layerId = "0f17b32804d3"74 val layerSize = 127L75 progressUpdatesReceived.forAtLeastOne {76 it.message shouldBe "Pulling from batect/docker-client"77 it.detail shouldBe null78 it.id shouldBeIn setOf(imageWithoutTag, imageWithoutTag.substringAfter('@')) // Older versions of Docker only return the digest here79 }80 progressUpdatesReceived shouldContain ImagePullProgressUpdate("Pulling fs layer", ImagePullProgressDetail(0, 0), layerId)81 // Docker does some rate limiting of progress updates, so to make this test more resilient to this non-determinism, we82 // consider the test passing if at least one of these updates is posted.83 progressUpdatesReceived shouldContainAnyOf setOf(84 ImagePullProgressUpdate("Downloading", ImagePullProgressDetail(0, layerSize), layerId),85 ImagePullProgressUpdate("Downloading", ImagePullProgressDetail(layerSize, layerSize), layerId),86 ImagePullProgressUpdate("Download complete", ImagePullProgressDetail(0, 0), layerId)87 )88 progressUpdatesReceived.forAtLeastOne {89 it.message shouldBe "Extracting"90 it.detail shouldNotBe null91 it.detail!!.total shouldBe layerSize92 it.id shouldBe layerId...

Full Screen

Full Screen

CovidCertificateConfigMapperTest.kt

Source:CovidCertificateConfigMapperTest.kt Github

copy

Full Screen

1package de.rki.coronawarnapp.appconfig.mapping2import com.google.protobuf.ByteString3import de.rki.coronawarnapp.appconfig.internal.ApplicationConfigurationInvalidException4import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid5import de.rki.coronawarnapp.server.protocols.internal.v2.DgcParameters6import de.rki.coronawarnapp.util.toProtoByteString7import io.kotest.assertions.throwables.shouldThrow8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.types.beInstanceOf11import okio.ByteString.Companion.toByteString12import org.joda.time.Duration13import org.junit.jupiter.api.Test14import testhelpers.BaseTest15class CovidCertificateConfigMapperTest : BaseTest() {16 private fun createInstance() = CovidCertificateConfigMapper()17 private val testReissueServicePublicKeyDigestByteString by lazy {18 "reissueServicePublicKeyDigest".toByteArray().toByteString().sha256()19 }20 private val testReissueServicePublicKeyDigestProtoByteString by lazy {21 testReissueServicePublicKeyDigestByteString.toProtoByteString()22 }23 @Test24 fun `values are mapped`() {25 val config = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()26 .setDgcParameters(27 DgcParameters.DGCParameters.newBuilder()28 .setTestCertificateParameters(29 DgcParameters.DGCTestCertificateParameters.newBuilder()30 .setWaitForRetryInSeconds(60)31 .setWaitAfterPublicKeyRegistrationInSeconds(60)32 )33 .setExpirationThresholdInDays(13)34 .setBlockListParameters(35 DgcParameters.DGCBlocklistParameters.newBuilder()36 .addBlockedUvciChunks(37 DgcParameters.DGCBlockedUVCIChunk.newBuilder()38 .addIndices(0)39 .setHash(40 ByteString.copyFrom(41 "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9",42 Charsets.UTF_843 )44 )45 )46 .build()47 )48 .setReissueServicePublicKeyDigest(testReissueServicePublicKeyDigestProtoByteString)49 )50 .build()51 createInstance().map(config).apply {52 testCertificate.waitAfterPublicKeyRegistration shouldBe Duration.standardSeconds(60)53 testCertificate.waitForRetry shouldBe Duration.standardSeconds(60)54 expirationThreshold shouldBe Duration.standardDays(13)55 reissueServicePublicKeyDigest shouldBe testReissueServicePublicKeyDigestByteString56 }57 }58 @Test59 fun `throws if dcc parameters are missing`() {60 val rawConfig = AppConfigAndroid.ApplicationConfigurationAndroid.getDefaultInstance()61 rawConfig.hasDgcParameters() shouldBe false62 shouldThrow<ApplicationConfigurationInvalidException> {63 createInstance().map(rawConfig = rawConfig)64 }.cause should beInstanceOf(IllegalStateException::class)65 }66 @Test67 fun `throws if reissueServicePublicKeyDigest is empty`() {68 val rawConfig = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()69 .setDgcParameters(DgcParameters.DGCParameters.getDefaultInstance())70 .build()71 rawConfig.hasDgcParameters() shouldBe true72 shouldThrow<ApplicationConfigurationInvalidException> {73 createInstance().map(rawConfig = rawConfig)74 }.cause should beInstanceOf(IllegalStateException::class)75 }76 @Test77 fun `defaults are returned if test certificate parameters are missing`() {78 val dgcParams = DgcParameters.DGCParameters.newBuilder()79 .setReissueServicePublicKeyDigest(testReissueServicePublicKeyDigestProtoByteString)80 val config = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()81 .setDgcParameters(dgcParams)82 .build()83 createInstance().map(config).apply {84 testCertificate.waitAfterPublicKeyRegistration shouldBe Duration.standardSeconds(10)85 testCertificate.waitForRetry shouldBe Duration.standardSeconds(10)86 expirationThreshold shouldBe Duration.standardDays(14)87 reissueServicePublicKeyDigest shouldBe testReissueServicePublicKeyDigestByteString88 }89 }90 @Test91 fun `values are checked for sanity`() {92 val config = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()93 .setDgcParameters(94 DgcParameters.DGCParameters.newBuilder()95 .setTestCertificateParameters(96 DgcParameters.DGCTestCertificateParameters.newBuilder()97 .setWaitForRetryInSeconds(61)98 .setWaitAfterPublicKeyRegistrationInSeconds(61)99 )100 .setReissueServicePublicKeyDigest(testReissueServicePublicKeyDigestProtoByteString)101 )102 .build()103 createInstance().map(config).apply {104 testCertificate.waitAfterPublicKeyRegistration shouldBe Duration.standardSeconds(10)105 testCertificate.waitForRetry shouldBe Duration.standardSeconds(10)106 expirationThreshold shouldBe Duration.standardDays(14)107 reissueServicePublicKeyDigest shouldBe testReissueServicePublicKeyDigestByteString108 }109 }110}...

Full Screen

Full Screen

JacocoDomainTest.kt

Source:JacocoDomainTest.kt Github

copy

Full Screen

...83 @Test84 fun `should generate snake case source object`() {85 val coverallsSourceFile = CoverallsSourceFile("name", "sourceDigest")86 val writeValueAsString = writeSnakeCaseJsonValueAsString(coverallsSourceFile)87 writeValueAsString.shouldBe("{\"name\":\"name\",\"source_digest\":\"sourceDigest\"}")88 }89 @Test90 fun `should generate snake case coveralls object`() {91 val coverallsSourceFile = CoverallsReport(92 "repoToken", "serviceName",93 mutableListOf(CoverallsSourceFile("name", "sourceDigest")),94 Git(95 Head("id", "authorName", "authorEmail", "committerName", "committerEmail"),96 "branch", listOf(Remote("remote", "url"))97 )98 )99 val writeValueAsString = writeSnakeCaseJsonValueAsString(coverallsSourceFile)100 writeValueAsString.shouldBe("{\"repo_token\":\"repoToken\",\"service_name\":\"serviceName\",\"source_files\":[{\"name\":\"name\",\"source_digest\":\"sourceDigest\"}],\"git\":{\"head\":{\"id\":\"id\",\"author_name\":\"authorName\",\"author_email\":\"authorEmail\",\"committer_name\":\"committerName\",\"committer_email\":\"committerEmail\",\"message\":null},\"branch\":\"branch\",\"remotes\":[{\"name\":\"remote\",\"url\":\"url\"}]}}")101 }102}...

Full Screen

Full Screen

ProofOfWorkTest.kt

Source:ProofOfWorkTest.kt Github

copy

Full Screen

23import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.shouldBe5import io.kotest.matchers.string.shouldStartWith6import org.apache.commons.codec.digest.DigestUtils7import java.lang.Math.random8import kotlin.math.pow910class ProofOfWorkTest : StringSpec({11 "proofOfWork() returns a value that meet the expectations" {12 val seed = random()13 proofOfWork(14 seed = seed,15 f = { a, b -> (a.pow(2) - b.pow(2)).let { DigestUtils.sha256Hex(it.toString()) } },16 isValid = { it.startsWith("0000") }17 ).apply {18 val hash = (this.pow(2) - seed.pow(2)).let { DigestUtils.sha256Hex(it.toString()) }19 hash shouldStartWith "0000"20 } ...

Full Screen

Full Screen

DigestMatchersTest.kt

Source:DigestMatchersTest.kt Github

copy

Full Screen

...4import io.kotest.matchers.shouldBe5import io.kotest.matchers.string.shouldHaveDigest6import io.kotest.matchers.string.shouldNotHaveDigest7class DigestMatchersTest : FunSpec({8 context("digest matchers") {9 test("string digest should match") {10 "cool for cats".shouldHaveDigest("md5", "cf6b4f4973077da736b50855f699d005")11 "cool for cats".shouldHaveDigest("SHA-256", "b3de79f07d214050325a260eeb512255243bfdabc1d1695419ae4b530a229bc4")12 "cool for cats".shouldNotHaveDigest("md5", "qwerty")13 "cool for cats".shouldNotHaveDigest("SHA-256", "qwerty")14 "".shouldHaveDigest("md5", "d41d8cd98f00b204e9800998ecf8427e")15 }16 test("return correct error message on failure") {17 shouldThrow<AssertionError> {18 "cool for cats".shouldHaveDigest("md5", "qwerty")19 }.message shouldBe "\"cool for cats\" should have md5 digest \"qwerty\" but was \"cf6b4f4973077da736b50855f699d005\""20 shouldThrow<AssertionError> {21 "cool for cats".shouldNotHaveDigest("md5", "cf6b4f4973077da736b50855f699d005")22 }.message shouldBe "\"cool for cats\" should not have md5 digest \"cf6b4f4973077da736b50855f699d005\""23 }24 }25})

Full Screen

Full Screen

MD5Test.kt

Source:MD5Test.kt Github

copy

Full Screen

...7class MD5Test : FreeSpec({8 "toString" {9 val testData = Arb.string().edgecases() + listOf("hogehoge")10 testData.forEach {11 val md5 = MD5.digest("hogehoge")12 println(md5.toString())13 println(md5.toStringOld())14 md5.toString() shouldBe md5.toStringOld()15 }16 }17})18private fun MD5.toStringOld(): String = String.format(19 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",20 bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],21 bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]22)...

Full Screen

Full Screen

UtilsTest.kt

Source:UtilsTest.kt Github

copy

Full Screen

...7 "hmac verification" {8 val crypto = require("crypto")9 val str = "Hello, world"10 val key = "key123"11 val expected = crypto.createHmac("sha256", key).update(str).digest("hex") as String12 val actual = str.hmacSha256(key)13 expected shouldBe actual14 }15})...

Full Screen

Full Screen

digest

Using AI Code Generation

copy

Full Screen

1val digest = Digest("SHA-256")2digest.digest("hello world") shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"3digest.digest("hello world".toByteArray()) shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"4val digest = Digest("SHA-256")5digest.digest("hello world") shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"6digest.digest("hello world".toByteArray()) shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"7val digest = Digest("SHA-256")8digest.digest("hello world") shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"9digest.digest("hello world".toByteArray()) shouldBe "f5b4f4c4e4a1c6e8a6a5a6b5d6b5d6e5e5d6b5d6b5d6b5d6b5d6b5d6b5d6b5"

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in digest

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful