#define _GNU_SOURCE #include "identity_api.h" #include "identity.h" #include #include #include #include #include static char names[4][48],accounts[4][20];static int count,fail_create; json_object *bindery_call(json_object *q){ json_object *o=json_object_new_object();const char *op=js(q,"op"); if(!strcmp(op,"identity-capabilities"))json_object_object_add(o,"identityVersion",json_object_new_int(1)); else if(!strcmp(op,"objects")){json_object *a=json_object_new_array();for(int i=0;i0);json_object *u=json_object_array_get_idx(users,0);char account[20];snprintf(account,sizeof account,"%s",js(u,"name"));int uid=json_object_get_int(get(u,"uid")),gid=json_object_get_int(get(u,"gid"));json_object_put(r); json_object *q=json_tokener_parse("{\"name\":\"ALICE\",\"password\":\"TESTPASS1\",\"sharedConfirmed\":true}");addstr(q,"unix","root");json_object_object_add(q,"uid",json_object_new_int(0));json_object_object_add(q,"gid",json_object_new_int(0));rejected(q); addstr(q,"unix",account);json_object_object_add(q,"uid",json_object_new_int(uid+1));json_object_object_add(q,"gid",json_object_new_int(gid));rejected(q); json_object_object_add(q,"uid",json_object_new_int(uid));json_object_object_add(q,"sharedConfirmed",json_object_new_boolean(0));rejected(q);json_object_object_add(q,"sharedConfirmed",json_object_new_boolean(1)); r=identity_create(q);assert(!get(r,"error")&&count==1);assert(!strcmp(js(r,"unix"),account));json_object_put(r);assert(identity_local_managed("ALICE"));rejected(q); addstr(q,"name","BOB");r=identity_create(q);assert(!get(r,"error")&&count==2);json_object_put(r);assert(!strcmp(accounts[0],accounts[1])); r=identity_status();assert(json_object_array_length(get(r,"localMappings"))==2);assert(!strcmp(js(json_object_array_get_idx(get(r,"localMappings"),0),"status"),"linked"));assert(!strstr(json_object_to_json_string(r),"TESTPASS1"));json_object_put(r); fail_create=1;addstr(q,"name","FAILED");rejected(q);assert(identity_local_managed("FAILED"));fail_create=0;rejected(q); sqlite3 *db;assert(!mars_id_open(&db,1));assert(sqlite3_exec(db,"UPDATE local_mappings SET uid=uid+1 WHERE name='ALICE'",NULL,NULL,NULL)==SQLITE_OK);sqlite3_close(db); r=identity_status();assert(!strcmp(js(json_object_array_get_idx(get(r,"localMappings"),0),"status"),"account-changed"));json_object_put(r); json_object_put(q);unlink(MARS_ID_DB);puts("PASS SQL local mappings: root/stale ID rejection, explicit confirmation, shared account, duplicates, failed reservation, identity drift, no passwords"); }