(t *testing.T)
| 166 | } |
| 167 | |
| 168 | func TestMasterKey_Encrypt(t *testing.T) { |
| 169 | mockParsedRecipient, err := parseRecipient(mockRecipient) |
| 170 | assert.NoError(t, err) |
| 171 | mockSshParsedRecipient, err := parseRecipient(mockSshRecipient) |
| 172 | assert.NoError(t, err) |
| 173 | |
| 174 | t.Run("recipient", func(t *testing.T) { |
| 175 | key := &MasterKey{ |
| 176 | Recipient: mockRecipient, |
| 177 | } |
| 178 | assert.NoError(t, key.Encrypt([]byte(mockEncryptedKeyPlain))) |
| 179 | assert.NotEmpty(t, key.EncryptedKey) |
| 180 | }) |
| 181 | |
| 182 | t.Run("recipient ssh", func(t *testing.T) { |
| 183 | key := &MasterKey{ |
| 184 | Recipient: mockSshRecipient, |
| 185 | } |
| 186 | assert.NoError(t, key.Encrypt([]byte(mockEncryptedKeyPlain))) |
| 187 | assert.NotEmpty(t, key.EncryptedKey) |
| 188 | }) |
| 189 | |
| 190 | t.Run("parsed recipient", func(t *testing.T) { |
| 191 | key := &MasterKey{ |
| 192 | parsedRecipient: mockParsedRecipient, |
| 193 | } |
| 194 | assert.NoError(t, key.Encrypt([]byte(mockEncryptedKeyPlain))) |
| 195 | assert.NotEmpty(t, key.EncryptedKey) |
| 196 | }) |
| 197 | |
| 198 | t.Run("parsed recipient ssh", func(t *testing.T) { |
| 199 | key := &MasterKey{ |
| 200 | parsedRecipient: mockSshParsedRecipient, |
| 201 | } |
| 202 | assert.NoError(t, key.Encrypt([]byte(mockEncryptedKeyPlain))) |
| 203 | assert.NotEmpty(t, key.EncryptedKey) |
| 204 | }) |
| 205 | |
| 206 | t.Run("invalid recipient", func(t *testing.T) { |
| 207 | key := &MasterKey{ |
| 208 | Recipient: "invalid", |
| 209 | } |
| 210 | err := key.Encrypt([]byte(mockEncryptedKeyPlain)) |
| 211 | assert.Error(t, err) |
| 212 | assert.ErrorContains(t, err, "failed to parse input, unknown recipient type:") |
| 213 | assert.Empty(t, key.EncryptedKey) |
| 214 | }) |
| 215 | |
| 216 | t.Run("parsed recipient and invalid recipient", func(t *testing.T) { |
| 217 | key := &MasterKey{ |
| 218 | Recipient: "invalid", |
| 219 | parsedRecipient: mockParsedRecipient, |
| 220 | } |
| 221 | // Validates mockParsedRecipient > Recipient |
| 222 | assert.NoError(t, key.Encrypt([]byte(mockEncryptedKeyPlain))) |
| 223 | assert.NotEmpty(t, key.EncryptedKey) |
| 224 | }) |
| 225 | } |
nothing calls this directly
no test coverage detected