mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 13:52:51 +00:00
# Which Problems Are Solved As part of #11035 , this PR implements the IDP intent check logic for session validation # How the Problems Are Solved - Inject encryption algorithm for IDP intent tokens at DB initialization - Add the IDP intent repository as an invoke option - Rework crypto mocks using gomock - Implement IDP intent check logic - minor - DB: expand IDP Intent deletion testing table with a test case where IDP intent is not found # Noteworthy I did not implement `domain.Transactional` given the doubts that @adlerhurst expressed in https://github.com/zitadel/zitadel/pull/11804 . So, there is no transaction AT ALL in here because the `Execute()` method contains one single DB call (Delete) and `Validate()` just does Get calls. # Additional Context This is a cherry-picked PR + minor changes, coming from https://github.com/zitadel/zitadel/pull/11164 - Relates to #11035 - Depends on https://github.com/zitadel/zitadel/pull/11804
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package crypto
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"go.uber.org/mock/gomock"
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func CreateMockEncryptionAlg(ctrl *gomock.Controller) EncryptionAlgorithm {
|
|
mCrypto := NewMockEncryptionAlgorithm(ctrl)
|
|
mCrypto.EXPECT().Algorithm().AnyTimes().Return("enc")
|
|
mCrypto.EXPECT().EncryptionKeyID().AnyTimes().Return("id")
|
|
mCrypto.EXPECT().DecryptionKeyIDs().AnyTimes().Return([]string{"id"})
|
|
mCrypto.EXPECT().Encrypt(gomock.Any()).AnyTimes().DoAndReturn(
|
|
func(code []byte) ([]byte, error) {
|
|
return code, nil
|
|
},
|
|
)
|
|
mCrypto.EXPECT().DecryptString(gomock.Any(), gomock.Any()).AnyTimes().DoAndReturn(
|
|
func(code []byte, keyID string) (string, error) {
|
|
if keyID != "id" {
|
|
return "", zerrors.ThrowInternal(nil, "id", "invalid key id")
|
|
}
|
|
return string(code), nil
|
|
},
|
|
)
|
|
mCrypto.EXPECT().Decrypt(gomock.Any(), gomock.Any()).AnyTimes().DoAndReturn(
|
|
func(code []byte, keyID string) ([]byte, error) {
|
|
if keyID != "id" {
|
|
return nil, zerrors.ThrowInternal(nil, "id", "invalid key id")
|
|
}
|
|
return code, nil
|
|
},
|
|
)
|
|
return mCrypto
|
|
}
|
|
|
|
func createMockCrypto(t *testing.T) EncryptionAlgorithm {
|
|
mCrypto := NewMockEncryptionAlgorithm(gomock.NewController(t))
|
|
mCrypto.EXPECT().Algorithm().AnyTimes().Return("crypto")
|
|
return mCrypto
|
|
}
|
|
|
|
func createMockGenerator(t *testing.T, crypto EncryptionAlgorithm) Generator {
|
|
mGenerator := NewMockGenerator(gomock.NewController(t))
|
|
mGenerator.EXPECT().Alg().AnyTimes().Return(crypto)
|
|
return mGenerator
|
|
}
|