Browse Source

test/test_ensure_passphrase.cc

ENGINE-781
Volker Birk 2 years ago
parent
commit
27ebfb3ba2
5 changed files with 70 additions and 23 deletions
  1. +5
    -1
      Makefile.conf
  2. +1
    -1
      passphrase_cache.cc
  3. +0
    -1
      passphrase_cache.hxx
  4. +7
    -20
      test/Makefile
  5. +57
    -0
      test/test_ensure_passphrase.cc

+ 5
- 1
Makefile.conf View File

@ -7,7 +7,7 @@ HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
PREFIX=$(HOME)
CXXFLAGS=-std=c++11 -fPIC -O0 $(ENGINE_INC)
CXXFLAGS1=-std=c++11 -fPIC -O0 $(ENGINE_INC)
# Build target
BUILD_FOR:=$(shell uname)
@ -47,3 +47,7 @@ endif
ifdef BUILD_CONFIG
include $(BUILD_CONFIG)
endif
ifndef ENGINE_TEST
ENGINE_TEST = \"$(HOME)/dev/pEpEngine/test\"
endif

+ 1
- 1
passphrase_cache.cc View File

@ -156,7 +156,7 @@ namespace pEp {
PEP_STATUS PassphraseCache::ensure_passphrase(PEP_SESSION session, std::string fpr)
{
PEP_STATUS status = PEP_STATUS_OK;
PEP_STATUS status;
for_each_passphrase([&](std::string passphrase) {
status = ::config_passphrase(session, passphrase.c_str());


+ 0
- 1
passphrase_cache.hxx View File

@ -1,4 +1,3 @@
#pragma once
#include "passphrase_cache.hh"
namespace pEp {


+ 7
- 20
test/Makefile View File

@ -2,28 +2,15 @@ include ../Makefile.conf
LDFLAGS=-L../ $(ENGINE_LIB)
LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter
CXXFLAGS+=-I../
CXXFLAGS+=-I../ $(ENGINE_INC) -std=c++11 -DENGINE_TEST=$(ENGINE_TEST)
.PHONY=all, test_adapter, test_adapter_cxx, test_library
SRC=$(wildcard test_*.cc)
TST=$(subst .cc,,$(SRC))
all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore test_message_cache
all: $(TST)
test_adapter: test_adapter.cc ../libpEpAdapter.a
test_adapter_cxx: test_adapter_cxx.cc ../libpEpAdapter.a
test_library: test_library.cc ../libpEpAdapter.a
test_passphrase_cache: test_passphrase_cache.cc ../libpEpAdapter.a
test_semaphore: test_semaphore.cc ../libpEpAdapter.a
test_message_cache: test_message_cache.cc ../libpEpAdapter.a
%: %.cc ../libpEpAdapter.a
clean:
rm -vf test_adapter
rm -rvf test_adapter.dSYM
rm -vf test_adapter_cxx
rm -rvf test_adapter_cxx.dSYM
rm -vf test_library
rm -rvf test_library.dSYM
rm -f $(TST)
rm -f *.dSYM

+ 57
- 0
test/test_ensure_passphrase.cc View File

@ -0,0 +1,57 @@
#include <iostream>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include "Adapter.hh"
#include "passphrase_cache.hh"
#include "status_to_string.hh"
#include <pEp/message_api.h>
#include <pEp/keymanagement.h>
using namespace pEp;
using namespace pEp::Adapter;
using namespace std;
void test()
{
passphrase_cache.add("erwin");
passphrase_cache.add("cathy");
passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
const char* erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570";
pEp_identity* bob = ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog");
PEP_STATUS status = ::set_own_key(session(), bob, bob_fpr);
pEp_identity* erwin = ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin");
status = ::set_own_key(session(), erwin, erwin_fpr);
::free_identity(bob);
::free_identity(erwin);
session(Adapter::release);
}
int main()
{
char path[MAXPATHLEN+1];
const char *templ = "/tmp/test_ensure_passphrase.XXXXXXXXXXXX";
strcpy(path, templ);
char *tmpdir = mkdtemp(path);
assert(tmpdir);
chdir(tmpdir);
setenv("HOME", path, 1);
cerr << "test directory: " << path << endl;
test();
return 0;
}

Loading…
Cancel
Save