MCPcopy Index your code
hub / github.com/getsops/sops / TestMasterKey_Encrypt

Function TestMasterKey_Encrypt

age/keysource_test.go:168–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func 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}

Callers

nothing calls this directly

Calls 3

EncryptMethod · 0.95
parseRecipientFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected