@@ -320,3 +320,44 @@ func TestRegisterKeys_WithoutEvalPart_ReturnsErr(t *testing.T) {
320320 t .Errorf ("ActivateKeys without KeyPartEval: got %v, want ErrKeysNotForRegister" , err )
321321 }
322322}
323+
324+ // TestKeysExist_PartsAware exercises the KeyParts-aware lookup. Vault's
325+ // agent-manifest delivery only ships EncKey to the client (Eval/Sec stay
326+ // in Vault), so the consumer opens that directory with
327+ // WithKeyParts(KeyPartEnc) and expects KeysExist to return true on an
328+ // Enc-only directory. The previous implementation walked all three slots
329+ // unconditionally and rejected the bundle.
330+ func TestKeysExist_PartsAware (t * testing.T ) {
331+ encOnly := func (t * testing.T ) string {
332+ t .Helper ()
333+ dir := t .TempDir ()
334+ if err := os .WriteFile (filepath .Join (dir , encKeyJSONFile ), []byte ("{}" ), 0o600 ); err != nil {
335+ t .Fatal (err )
336+ }
337+ return dir
338+ }
339+
340+ t .Run ("enc-only dir + WithKeyParts(KeyPartEnc) → true" , func (t * testing.T ) {
341+ dir := encOnly (t )
342+ opts := append (baseKeyOpts (dir ), WithKeyParts (KeyPartEnc ))
343+ if ! KeysExist (opts ... ) {
344+ t .Error ("KeysExist with KeyPartEnc must accept Enc-only directory" )
345+ }
346+ })
347+
348+ t .Run ("enc-only dir + default parts (= all three) → false" , func (t * testing.T ) {
349+ dir := encOnly (t )
350+ // No WithKeyParts → resolveKeyParts treats it as all three required.
351+ if KeysExist (baseKeyOpts (dir )... ) {
352+ t .Error ("default parts must require all 3 slots" )
353+ }
354+ })
355+
356+ t .Run ("enc-only dir + WithKeyParts(KeyPartEval) → false (eval missing)" , func (t * testing.T ) {
357+ dir := encOnly (t )
358+ opts := append (baseKeyOpts (dir ), WithKeyParts (KeyPartEval ))
359+ if KeysExist (opts ... ) {
360+ t .Error ("requesting Eval on an Enc-only dir must fail" )
361+ }
362+ })
363+ }
0 commit comments