GithubHelp home page GithubHelp logo

Comments (6)

cternes avatar cternes commented on September 21, 2024

You code is quite confusing.What are you trying to achieve?

Actually the following line does nothing, because you're not using the result of the build method:

 new GroupBuilder(keePassFile.getRoot().getGroups().get(0)).addEntry(enrty).build();

Maybe it could help if you would take a look into the unit tests of the project to get familiar with the api.

from openkeepass.

yososs avatar yososs commented on September 21, 2024

I open an existing database file, and some update, want to write to a new file. Test code is already read.

Did you look at the results that were actually run the test code written by me?

new GroupBuilder(keePassFile.getRoot().getGroups().get(0)).addEntry(enrty).build();

In fact, the new entry is registered in the database file.

However, like the write method it has side effects, made to state the password is encoded in the entry of KeePassFile instance.

The correct update how I want you to explain in index.md.

from openkeepass.

cternes avatar cternes commented on September 21, 2024

Thanks, I've got your point. I agree that entries should not be modified during writing.

from openkeepass.

yososs avatar yososs commented on September 21, 2024

This fix does not pass my test code.
I will pull request.

from openkeepass.

cternes avatar cternes commented on September 21, 2024

@yososs I've implemented your test in method shouldEnsureThatEntriesAreNotModifiedDuringWriting(). Can you tell me why this does method does not fulfill your requirement?

from openkeepass.

yososs avatar yososs commented on September 21, 2024

Because it does not pass the following line, which I wrote, it was investigated.

Assert.assertEquals("password", keePassFile.getRoot().getGroups().get(0).getEntries().get(0).getPassword());
Since this line is to pass and to comment out the write () method, it is obvious there are still side effects.

  • Looking at the original correction code, but have created a clone, not a clone instance to the input of the toXML method.

return new KeePassDatabaseXmlParser().toXml(keePassFile).toByteArray();


    private byte[] marshallXml(KeePassFile keePassFile, KeePassHeader header) {
        KeePassFile clonedKeePassFile = new GroupZipper(keePassFile).cloneKeePassFile();

        ProtectedStringCrypto protectedStringCrypto = Salsa20.createInstance(header.getProtectedStreamKey());
        new ProtectedValueProcessor().processProtectedValues(new EncryptionStrategy(protectedStringCrypto), clonedKeePassFile);

        return new KeePassDatabaseXmlParser().toXml(keePassFile).toByteArray();
    }

Believes that there is a problem with the test, I was plus written to test code written by you.

    @Test
    public void shouldEnsureThatEntriesAreNotModifiedDuringWriting () {
        // Open DB
        . Final KeePassFile keePassFile = KeePassDatabase.getInstance ( "target / test-classes / testDatabase.kdbx") openDatabase ( "abcdefg");
        Group generalGroup = keePassFile.getGroupByName ( "General");

        // Add entry
        ... Entry entry = new EntryBuilder (UUID.randomUUID ()) title ( "title") password ( "password") build ();
        new GroupBuilder (generalGroup) .addEntry (entry) .build ();

        // Compare password in current DB
        Assert.assertEquals (. Entry.getPassword (), generalGroup.getEntryByTitle ( "title") getPassword ());

        // Get origin passwords
        List <String> originPasswords = new ArrayList <String> ();
        List <Entry> entries = keePassFile.getEntries ();
        for (Entry e: entries) {
            originPasswords.add (e.getPassword ());
        }

        // Write to new DB
        KeePassDatabase.write (keePassFile, "abcdefg", "target / test-classes / testDatabase_new.kdbx");

        // Get final passwords
        List <String> finalPasswords = new ArrayList <String> ();
        for (Entry e: entries) {
            finalPasswords.add (e.getPassword ());
        }

        // Compare original passwords with final ones
        assertThat (finalPasswords, is (originPasswords));




        // Add by Yos ---------------------------------------------- -----------------------------
        List <String> finalPasswords2 = new ArrayList <String> ();
        List <Entry> entries2 = keePassFile.getEntries ();
        for (Entry e: entries2) {
        finalPasswords2.add (e.getPassword ());
        }

        assertThat (originPasswords, is (finalPasswords2));

    }

from openkeepass.

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.