Skip to content

Instantly share code, notes, and snippets.

View OleksandrKucherenko's full-sized avatar

Oleksandr OleksandrKucherenko

View GitHub Profile
@Test
@Config(sdk = Build.VERSION_CODES.KITKAT)
public void testExtractFacebookConceal_NoHardware_api19() throws Exception {
// GIVEN:
// API19, minimal Android version
final ReactApplicationContext context = getRNContext();
// WHEN: ask keychain for secured storage
final KeychainModule module = new KeychainModule(context);
package com.oblador.keychain;
import javax.crypto.KeyGeneratorSpi;
import javax.crypto.SecretKey;
public abstract class FakeKeyGeneratorSpi extends KeyGeneratorSpi {
@Override
protected SecretKey engineGenerateKey() {
return doEngineGenerateKey();
}
package com.oblador.keychain;
import android.security.keystore.KeyInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.mockito.MockSettings;
import org.mockito.Mockito;
package com.oblador.keychain;
import java.security.Provider;
import java.util.HashMap;
public final class FakeProvider extends Provider {
public static final String NAME = "AndroidKeyStore";
public final HashMap<String, HashMap<String, MocksForProvider>> mocks = new HashMap<>();
public final HashMap<String, Object> configuration = new HashMap<>();
// https://gist.github.com/OleksandrKucherenko/34b5c72445bcf9d5519af6898afcb8fb#file-keychainmoduletests-java-L87-L92
@RunWith(RobolectricTestRunner.class)
public class KeychainModuleTests {
/**
* Security fake provider.
*/
private FakeProvider provider = new FakeProvider();
@Before
package com.oblador.keychain;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
@OleksandrKucherenko
OleksandrKucherenko / build.gradle.kts
Created February 7, 2020 11:04
Custom tasks that synchronise library source code with Sample that demonstrate library usage
val updateLibrarySourcesInExample by tasks.registering(Copy::class) {
into("${rootProject.projectDir}/KeychainExample/node_modules/react-native-keychain/")
from("${rootProject.projectDir}/android/src/"){
into("android/src")
}
from("${rootProject.projectDir}/typings/"){
into("typings")
}
@OleksandrKucherenko
OleksandrKucherenko / build.gradle
Last active April 11, 2022 21:06
repack AAR with different types of compatibility things, like: androidx vs support library, include/exclude/repackage aar during compilation
/** Copyright: 2019-*, Oleksandr Kucherenko (olku@artfulbits.se) */
apply plugin: 'com.android.library'
android {
/* ... default android lib OR app configuration ... */
}
configurations {
repack { transitive = false }
compatibility { transitive = false }
// Force Jacoco Agent version upgrade
subprojects {
configurations.all {
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "${jacocoVersion}"
}
}
}
buildscript {
ext {
jacocoVersion = project.JACOCO_VERSION
}
dependencies {
// To confirm JaCoCo version run: $ ./gradlew buildEnvironment
//region classpath "org.jacoco:org.jacoco.core:${jacocoVersion}"
// Resolves issue of incorrect version use in one of jacoco/android plugin inner tasks
classpath "org.jacoco:org.jacoco.core:${jacocoVersion}"
classpath "org.jacoco:org.jacoco.report:${jacocoVersion}"