fixed enable_identity_for_sync - internal _myself CANNOT be used for DB ident gen if keygen is disabled. sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 29 Jan 2020 20:36:45 +0100
branchsync
changeset 4369182b2079bfcd
parent 4368 d69ffc8666be
child 4370 f98be114ea22
fixed enable_identity_for_sync - internal _myself CANNOT be used for DB ident gen if keygen is disabled.
src/sync_api.c
test/src/SyncTest.cc
     1.1 --- a/src/sync_api.c	Tue Jan 28 22:44:53 2020 +0100
     1.2 +++ b/src/sync_api.c	Wed Jan 29 20:36:45 2020 +0100
     1.3 @@ -264,16 +264,22 @@
     1.4      if (!(session && ident))
     1.5          return PEP_ILLEGAL_VALUE;
     1.6  
     1.7 -    // create the identity in the database if it is not yet there.
     1.8 -    // This generates no events.
     1.9 +    // Find out if flags are already set. If there's no identity, this won't
    1.10 +    // create one.
    1.11      PEP_STATUS status = _myself(session, ident, false, true, false);
    1.12 +    if (status != PEP_STATUS_OK && status != PEP_KEY_NOT_FOUND && status != PEP_GET_KEY_FAILED)
    1.13 +        return status;
    1.14 +
    1.15 +    if ((ident->flags & PEP_idf_devicegroup) && !(ident->flags & PEP_idf_not_for_sync))
    1.16 +        return PEP_STATUS_OK;
    1.17 +
    1.18 +    // Ok, this is kind of annoying - if the flags aren't set, we won't create 
    1.19 +    // a keygen event anyway, so we're going to have to call myself and issue 
    1.20 +    // an unconditional keygen event.
    1.21 +    status = myself(session, ident);
    1.22      if (status != PEP_STATUS_OK)
    1.23          return status;
    1.24  
    1.25 -    // if identity is already enabled for sync do nothing
    1.26 -    if ((ident->flags & PEP_idf_devicegroup) && !(ident->flags & PEP_idf_not_for_sync))
    1.27 -        return PEP_STATUS_OK;
    1.28 -
    1.29      status = unset_identity_flags(session, ident, PEP_idf_not_for_sync);
    1.30      if (status != PEP_STATUS_OK) // explicit. sorry, but lazy makes mistakes in C
    1.31          return status;
    1.32 @@ -282,22 +288,7 @@
    1.33      if (status != PEP_STATUS_OK)
    1.34          return status;
    1.35  
    1.36 -    // Let's make sure whatever flags are on the retval are at least correct
    1.37 -    // so as to unnecessary reduce dev freakout.
    1.38 -    ident->flags = (ident->flags | PEP_idf_devicegroup) & ~PEP_idf_not_for_sync;
    1.39 -
    1.40 -    // If no key was actually in the DB, make one now.
    1.41 -    // This will trigger a sync event. 
    1.42 -    if (EMPTYSTR(ident->fpr)) {
    1.43 -        status = _myself(session, ident, true, true, false);
    1.44 -        if (status != PEP_STATUS_OK)
    1.45 -            return status;
    1.46 -    }
    1.47 -    else {
    1.48 -        // Ok, we actually had a key. We pretend we generated one to make 
    1.49 -        // sync play nice.
    1.50 -        signal_Sync_event(session, Sync_PR_keysync, KeyGen, NULL);
    1.51 -    }        
    1.52 +    signal_Sync_event(session, Sync_PR_keysync, KeyGen, NULL);
    1.53  
    1.54      return PEP_STATUS_OK;
    1.55  }
     2.1 --- a/test/src/SyncTest.cc	Tue Jan 28 22:44:53 2020 +0100
     2.2 +++ b/test/src/SyncTest.cc	Wed Jan 29 20:36:45 2020 +0100
     2.3 @@ -265,3 +265,21 @@
     2.4      output_stream << "check_sync(): cry for unknown key\n";
     2.5      signal_Sync_event(sync, Sync_PR_keysync, CannotDecrypt, NULL);
     2.6  }
     2.7 +
     2.8 +TEST_F(SyncTest, check_sync_enable)
     2.9 +{
    2.10 +    pEp_identity* julio = new_identity("julio.iglesias@truhan.senor.es", NULL, PEP_OWN_USERID, "Julio Iglesias");
    2.11 +    enable_identity_for_sync(session, julio);
    2.12 +    adapter.processing();
    2.13 +    myself(session, julio);
    2.14 +    ASSERT_EQ(julio->flags, PEP_idf_devicegroup);
    2.15 +    string current_fpr = julio->fpr;
    2.16 +
    2.17 +// Passes if you step through and ignore the send_key_to_recents part of key reset, because the attempt to pass the static class vars above doesn't work.
    2.18 +// FIXME: KB, reimplement according to now-standard method used in key reset tests
    2.19 +//    disable_identity_for_sync(session, julio);
    2.20 +//    adapter.processing();
    2.21 +//    myself(session, julio);
    2.22 +//    ASSERT_EQ(julio->flags, PEP_idf_not_for_sync);
    2.23 +//    ASSERT_STRNE(current_fpr.c_str(), julio->fpr);
    2.24 +}