mirror of
				https://github.com/optim-enterprises-bv/databunker.git
				synced 2025-10-31 18:07:47 +00:00 
			
		
		
		
	add tests
This commit is contained in:
		| @@ -173,18 +173,20 @@ func (dbobj dbcon) getAuditEvent(atoken string) (string, []byte, error) { | |||||||
| 				} | 				} | ||||||
| 				result := fmt.Sprintf(`{"before":%s,"after":%s,"debug":"%s"}`, before2, after2, debug) | 				result := fmt.Sprintf(`{"before":%s,"after":%s,"debug":"%s"}`, before2, after2, debug) | ||||||
| 				return userTOKEN, []byte(result), nil | 				return userTOKEN, []byte(result), nil | ||||||
| 			} else if len(after) > 0 { | 			} | ||||||
|  | 			if len(after) > 0 { | ||||||
| 				after2, _ := dbobj.userDecrypt(userTOKEN, after) | 				after2, _ := dbobj.userDecrypt(userTOKEN, after) | ||||||
| 				log.Printf("after: %s", after2) | 				log.Printf("after: %s", after2) | ||||||
| 				record["after"] = after2 | 				record["after"] = after2 | ||||||
| 				result := fmt.Sprintf(`{"after":%s,"debug":"%s"}`, after2, debug) | 				result := fmt.Sprintf(`{"after":%s,"debug":"%s"}`, after2, debug) | ||||||
| 				return userTOKEN, []byte(result), nil | 				return userTOKEN, []byte(result), nil | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 			if len(debug) > 0 { | 			if len(debug) > 0 { | ||||||
| 				result := fmt.Sprintf(`{"debug":"%s"}`, debug) | 				result := fmt.Sprintf(`{"debug":"%s"}`, debug) | ||||||
| 				return userTOKEN, []byte(result), nil | 				return userTOKEN, []byte(result), nil | ||||||
| 			} | 			} | ||||||
| 	return userTOKEN, nil, nil | 			return userTOKEN, []byte("{}"), nil | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return userTOKEN, nil, errors.New("not found") | ||||||
| } | } | ||||||
|   | |||||||
| @@ -85,7 +85,7 @@ func TestCreateUpdateUser(t *testing.T) { | |||||||
| 	if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" { | 	if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" { | ||||||
| 		t.Fatalf("Lookup by login should fail now") | 		t.Fatalf("Lookup by login should fail now") | ||||||
| 	} | 	} | ||||||
| 	raw, _ = helpGetUserAuditEvents(userTOKEN, "?limit=1") | 	raw, _ = helpGetUserAuditEvents(userTOKEN, "?offset=1&limit=1") | ||||||
| 	if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" { | 	if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" { | ||||||
| 		t.Fatalf("Failed to get audit event/s\n") | 		t.Fatalf("Failed to get audit event/s\n") | ||||||
| 	} | 	} | ||||||
| @@ -103,13 +103,20 @@ func TestCreateUpdateUser(t *testing.T) { | |||||||
| 		t.Fatalf("Failed to extract atoken\n") | 		t.Fatalf("Failed to extract atoken\n") | ||||||
| 	} | 	} | ||||||
| 	fmt.Printf("Audit record: %s\n", atoken) | 	fmt.Printf("Audit record: %s\n", atoken) | ||||||
| 	raw3, _ := helpGetUserAuditEvent(atoken) | 	raw, _ = helpGetUserAuditEvent(atoken) | ||||||
| 	if raw3["status"].(string) != "ok" { | 	if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" { | ||||||
| 		t.Fatalf("Failed to get specific audit event\n") | 		t.Fatalf("Failed to get specific audit event\n") | ||||||
| 	} | 	} | ||||||
|  | 	oldRootToken := rootToken | ||||||
|  | 	rootToken, _ = uuid.GenerateUUID() | ||||||
|  | 	raw, _ = helpGetUserAuditEvent(atoken) | ||||||
|  | 	if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" { | ||||||
|  | 		t.Fatalf("Should failed to get specific audit event\n") | ||||||
|  | 	} | ||||||
|  | 	rootToken = oldRootToken | ||||||
| 	helpDeleteUser("token", userTOKEN) | 	helpDeleteUser("token", userTOKEN) | ||||||
| 	raw4, _ := helpGetUser("token", userTOKEN) | 	raw, _ = helpGetUser("token", userTOKEN) | ||||||
| 	d := raw4["data"].(map[string]interface{}) | 	d := raw["data"].(map[string]interface{}) | ||||||
| 	if len(d) != 0 { | 	if len(d) != 0 { | ||||||
| 		t.Fatalf("Failed to delete user") | 		t.Fatalf("Failed to delete user") | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Yuli
					Yuli