Giter Club home page Giter Club logo

Comments (7)

scottyab avatar scottyab commented on May 30, 2024

Not tried with Robolectric (will add to my todo), which version of shared prefs? 0.1.0 or the older 0.4.0?

from secure-preferences.

ntarocco avatar ntarocco commented on May 30, 2024

0.0.4, I can try to see if with the version 0.1.0 the problem is not reproducible...

from secure-preferences.

scottyab avatar scottyab commented on May 30, 2024

Are you sure you're tests are being correctly cleared down afterwards? I found with the unit tests I wrote in the lib, i had to manually delete the created pref xml files between tests otherwise it would reuse.

from secure-preferences.

pivotal-csaa-dev avatar pivotal-csaa-dev commented on May 30, 2024

We saw the same issue. We worked around it by manually setting the private static SharedPreferences field to null before each test. So, the root issue is because the SecurePreferences class uses the static field, so suppling a different filename will get ignored if SecurePreferences was instantiated with a different file name in a test that ran before this one. We suspect that the sFile variable being static may be a mistake due the comment above it: //default for testing

Here's our subclass that allows us to reset the static field before instantiating SecurePreferences again:

public class TestSafeSecurePreferences extends SecurePreferences {

    public TestSafeSecurePreferences(Context context) {
        super(context);
    }

    public TestSafeSecurePreferences(Context context, String password, String sharedPrefFilename) {
        super(context, password, sharedPrefFilename);
    }

    public static void clearStaticState() {
        try {
            Field staticField = SecurePreferences.class.getDeclaredField("sFile");
            staticField.setAccessible(true);
            staticField.set(null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

from secure-preferences.

scottyab avatar scottyab commented on May 30, 2024

Thanks for this see #22, a fix will be in version 0.1.2

from secure-preferences.

pivotal-csaa-dev avatar pivotal-csaa-dev commented on May 30, 2024

Cool!. Do you have a target release date for version 0.1.2?

from secure-preferences.

scottyab avatar scottyab commented on May 30, 2024

@pivotal-csaa-dev 0.1.2 has been pushed to maven central, awaiting replication.

from secure-preferences.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.