If you're looking here, you're probably in trouble. Here's what you need to do: 1. Get the current CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS environment variable. 2. Run the following command: ENCRYPT_ME=" " CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS=" " go test -v -count=1 ./
(t *testing.T)
| 99 | // ENCRYPT_ME="<value to encrypt>" CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS="<secret keys here>" go test -v -count=1 ./enterprise/dbcrypt -test.run='^TestHelpMeEncryptSomeValue$' |
| 100 | // 3. Copy the value from the test output and do what you need with it. |
| 101 | func TestHelpMeEncryptSomeValue(t *testing.T) { |
| 102 | t.Parallel() |
| 103 | valueToEncrypt := os.Getenv("ENCRYPT_ME") |
| 104 | if valueToEncrypt == "" { |
| 105 | t.Skip("Set ENCRYPT_ME to some value you need to encrypt") |
| 106 | } |
| 107 | t.Logf("valueToEncrypt: %q", valueToEncrypt) |
| 108 | keys := os.Getenv("CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS") |
| 109 | require.NotEmpty(t, keys, "Set the CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS environment variable to use this") |
| 110 | |
| 111 | base64Keys := strings.Split(keys, ",") |
| 112 | activeKey := base64Keys[0] |
| 113 | |
| 114 | decodedKey, err := base64.StdEncoding.DecodeString(activeKey) |
| 115 | require.NoError(t, err, "the active key should be valid base64") |
| 116 | |
| 117 | cipher, err := cipherAES256(decodedKey) |
| 118 | require.NoError(t, err) |
| 119 | |
| 120 | t.Logf("cipher digest: %+v", cipher.HexDigest()) |
| 121 | |
| 122 | encryptedEmptyString, err := cipher.Encrypt([]byte(valueToEncrypt)) |
| 123 | require.NoError(t, err) |
| 124 | |
| 125 | t.Logf("encrypted and base64-encoded: %q", base64.StdEncoding.EncodeToString(encryptedEmptyString)) |
| 126 | } |
nothing calls this directly
no test coverage detected