rogerluan/arkana

View on GitHub
lib/arkana/templates/kotlin/arkana_tests.kt.erb

Summary

Maintainability
Test Coverage
<% require_relative "lib/arkana/helpers/string" %>
<% require_relative "lib/arkana/helpers/kotlin_template_helper" %>
// DO NOT MODIFY
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)
package <%= @kotlin_package_name %>


import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue

internal class <%= @namespace %>Test {
    private val salt = listOf(<%= @salt.formatted %>)
    private val globalSecrets = <%= @namespace %>.Global

    @Test
    fun test_decodeRandomHexKey_shouldDecode() {
<% hex_key = SecureRandom.hex(64) %>
<% secret = generate_test_secret(key: hex_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "<%= hex_key %>")
    }

    @Test
    fun test_decodeRandomBase64Key_shouldDecode() {
<% base64_key = SecureRandom.base64(64) %>
<% secret = generate_test_secret(key: base64_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "<%= base64_key %>")
    }

    @Test
    fun test_decodeUUIDKey_shouldDecode() {
<% uuid_key = SecureRandom.uuid %>
<% secret = generate_test_secret(key: uuid_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "<%= uuid_key %>")
    }

    @Test
    fun test_decodeTrueBoolValue_shouldDecode() {
<% bool_key = "true" %>
<% secret = generate_test_secret(key: bool_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertTrue(<%= @namespace %>.decodeBoolean(encoded = encoded, cipher = salt))
    }

    @Test
    fun test_decodeFalseBoolValue_shouldDecode() {
<% bool_key = "false" %>
<% secret = generate_test_secret(key: bool_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertFalse(<%= @namespace %>.decodeBoolean(encoded = encoded, cipher = salt))
    }

    @Test
    fun test_decodeIntValue_shouldDecode() {
<% int_key = "42" %>
<% secret = generate_test_secret(key: int_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decodeInt(encoded = encoded, cipher = salt), 42)
    }

    @Test
    fun test_decodeIntValueWithLeadingZeroes_shouldDecodeAsString() {
<% int_with_leading_zeroes_key = "0001" %>
<% secret = generate_test_secret(key: int_with_leading_zeroes_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "0001")
    }

    @Test
    fun test_decodeMassiveIntValue_shouldDecodeAsString() {
<% int_with_massive_number_key = "92233720368547758079223372036854775807" %>
<% secret = generate_test_secret(key: int_with_massive_number_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "92233720368547758079223372036854775807")
    }

    @Test
    fun test_decodeNegativeIntValue_shouldDecodeAsString() {
<% negative_int_key = "-42" %>
<% secret = generate_test_secret(key: negative_int_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "-42")
    }

    @Test
    fun test_decodeFloatingPointValue_shouldDecodeAsString() {
<% float_key = "3.14" %>
<% secret = generate_test_secret(key: float_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "3.14")
    }

    @Test
    fun test_encodeAndDecodeValueWithDollarSign_shouldDecode() {
<% dollar_sign_key = "real_$lim_shady" %>
<% secret = generate_test_secret(key: dollar_sign_key) %>
        val encoded = listOf(<%= secret.encoded_value %>)
        assertEquals(<%= @namespace %>.decode(encoded = encoded, cipher = salt), "real_\$lim_shady")
    }
<% if ENV["ARKANA_RUNNING_CI_INTEGRATION_TESTS"] %>

    @Test
    fun test_decodeEnvVarFromDotfile_withDollarSign__andEscaped_andNoQuotes_shouldDecode() {
        assertEquals(globalSecrets.secretWithDollarSignEscapedAndAndNoQuotesKey, "real_\$lim_shady")
    }

    @Test
    fun test_decodeEnvVarFromDotfile_withDollarSign__andEscaped_andDoubleQuotes_shouldDecode() {
        assertEquals(globalSecrets.secretWithDollarSignEscapedAndDoubleQuoteKey, "real_\$lim_shady")
    }

    @Test
    fun test_decodeEnvVarFromDotfile_withDollarSign__andNotEscaped_andSingleQuotes_shouldDecode() {
        assertEquals(globalSecrets.secretWithDollarSignNotEscapedAndSingleQuoteKey, "real_\$lim_shady")
    }

    @Test
    fun test_decodeEnvVarFromDotfile_withDollarSign__andNotEscaped_andDoubleQuotes_shouldDecodeWithUnexpectedValue() {
        assertNotEquals(globalSecrets.secretWithDollarSignNotEscapedAndDoubleQuotesKey, "real_\$lim_shady")
    }

    @Test
    fun test_decodeEnvVarFromDotfile_withDollarSign__andNotEscaped_andNoQuotes_shouldDecodeWithUnexpectedValue() {
        assertNotEquals(globalSecrets.secretWithDollarSignNotEscapedAndNoQuotesKey, "real_\$lim_shady")
    }

    @Test
    fun test_decodeEnvVarFromDotfile_withWeirdCharacters_shouldDecode() {
        assertEquals(globalSecrets.secretWithWeirdCharactersKey, "` ~ ! @ # % ^ & * ( ) _ - + = { [ } } | : ; ' < , > . ? /")
    }
<% end %>
}