diff --git a/Modules/ConfigLib/Sources/ConfigLib/Configuration/Util/SignatureVerifier/SignatureVerifier.swift b/Modules/ConfigLib/Sources/ConfigLib/Configuration/Util/SignatureVerifier/SignatureVerifier.swift index 6bb1f4b2..386aa005 100644 --- a/Modules/ConfigLib/Sources/ConfigLib/Configuration/Util/SignatureVerifier/SignatureVerifier.swift +++ b/Modules/ConfigLib/Sources/ConfigLib/Configuration/Util/SignatureVerifier/SignatureVerifier.swift @@ -49,24 +49,25 @@ struct SignatureVerifier { // MARK: - PEM / Base64 helpers private static func parsePublicKeyDER(fromPEM pem: String) throws -> Data { - let cleaned = removeAllWhitespace(data: pem) - let possibleHeaders = [ - ("-----BEGINPUBLICKEY-----", "-----ENDPUBLICKEY-----"), - ("-----BEGINECPUBLICKEY-----", "-----ENDECPUBLICKEY-----") + ("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----"), + ("-----BEGIN EC PUBLIC KEY-----", "-----END EC PUBLIC KEY-----") ] guard let (begin, end) = possibleHeaders.first( - where: { cleaned.contains($0.0) && cleaned.contains($0.1) } + where: { (begin, end) in + pem.contains(begin) && pem.contains(end) + } ) else { throw SignatureVerifierError.invalidPEM } - let base64Payload = cleaned + let payload = pem .replacing(begin, with: "") .replacing(end, with: "") - return try decodeBase64(base64Payload) + let cleaned = removeAllWhitespace(data: payload) + return try decodeBase64(cleaned) } private static func decodeBase64(_ value: String) throws -> Data { @@ -78,7 +79,7 @@ struct SignatureVerifier { } private static func removeAllWhitespace(data: String) -> String { - data.filter { !" \n\t\r".contains($0) } + data.filter { !$0.isWhitespace && !$0.isNewline } } // MARK: - ECDSA verify (curve chosen by DER length heuristic) diff --git a/RIADigiDoc.xcodeproj/project.pbxproj b/RIADigiDoc.xcodeproj/project.pbxproj index 02e7fff7..7f413656 100644 --- a/RIADigiDoc.xcodeproj/project.pbxproj +++ b/RIADigiDoc.xcodeproj/project.pbxproj @@ -117,6 +117,7 @@ DF3E4A862CE2C54600137235 /* CommonsLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = CommonsLib; sourceTree = ""; }; DF3E4A872CE2C5B500137235 /* LibdigidocLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = LibdigidocLib; sourceTree = ""; }; DF4E43C12D0BA38600967997 /* FileImportShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileImportShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + DF5CDD242F2BB42C002AB47F /* run-ci-tests.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "run-ci-tests.sh"; sourceTree = ""; }; DF64D0E12EC363C200FF73C6 /* SmartIdLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = SmartIdLib; sourceTree = ""; }; DF67D4F92D28531600F09EB9 /* ConfigLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = ConfigLib; sourceTree = ""; }; DFA16B492CD18C7C0099D34F /* libdigidoclib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = libdigidoclib.xcodeproj; sourceTree = ""; }; @@ -482,6 +483,7 @@ 1A438FD12E7224CE00546B86 /* scripts */ = { isa = PBXGroup; children = ( + DF5CDD242F2BB42C002AB47F /* run-ci-tests.sh */, 1AD26AB72E7AB14200A3629D /* build-libcdoc-sim.sh */, 1A7D36992E79EB8000CAD7A6 /* build-xcframeworks.sh */, 1A3E9ED22E79D35E00033299 /* build-openldap-iphonesimulator.sh */, diff --git a/codemagic.yaml b/codemagic.yaml index ec6f78be..9035f10c 100644 --- a/codemagic.yaml +++ b/codemagic.yaml @@ -147,10 +147,7 @@ workflows: script: | sh scripts/GenerateMocks.sh - xcode-project run-tests \ - --project RIADigiDoc.xcodeproj \ - --scheme AllTests \ - --device "iPhone 17" + sh scripts/run-ci-tests.sh when: condition: ${{ inputs.enableTests_input }} - name: Increment build number @@ -277,12 +274,9 @@ workflows: script: xcode-project use-profiles - name: Run tests script: | - sh scripts/GenerateMocks.sh + sh scripts/GenerateMocks.sh - xcode-project run-tests \ - --project RIADigiDoc.xcodeproj \ - --scheme AllTests \ - --device "iPhone 17" + sh scripts/run-ci-tests.sh - *get_app_version - name: Increment build number script: | diff --git a/scripts/run-ci-tests.sh b/scripts/run-ci-tests.sh new file mode 100644 index 00000000..184e666a --- /dev/null +++ b/scripts/run-ci-tests.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +# ----------------------------- +# Config +# ----------------------------- +PROJECT="RIADigiDoc.xcodeproj" +SCHEME="AllTests" +DEVICE="iPhone 17" + +COMMON_ARGS=( + --project "$PROJECT" + --scheme "$SCHEME" + --device "$DEVICE" + --disable-coverage + --max-concurrent-devices 1 + --max-concurrent-simulators 1 +) + +MODULE_GROUPS=( + "SmartIdLibTests" + "ConfigLibTests" + "MobileIdLibTests" + "LibdigidocLibTests" + "RIADigiDocTests" + "FileImportShareExtensionTests" + "UtilsLibTests" +) + +# ----------------------------- +# Reset simulators +# ----------------------------- +echo "Shutting down and erasing all simulators..." +xcrun simctl shutdown all || true +xcrun simctl erase all || true + +# ----------------------------- +# Run tests group by group +# ----------------------------- +for GROUP in "${MODULE_GROUPS[@]}"; do + echo "----------------------------------------" + echo "Running test group: $GROUP" + echo "----------------------------------------" + + TEST_XCARGS="$COMMON_XCARGS" + for MODULE in $GROUP; do + TEST_XCARGS+=" -only-testing:${MODULE}" + done + + xcode-project run-tests \ + "${COMMON_ARGS[@]}" \ + --test-xcargs "$TEST_XCARGS" + +done + +echo "All test groups completed successfully!"