Exemple #1
0
func TestCryptoPasswordStrength(t *testing.T) {
	passwords := []string{"mypassword", "summertablecactus+", "osome+#,,brassford"}
	for _, password := range passwords {
		fmt.Println("---------- Password:"******"-------------")
		utils.PrintJSON(DeterminePasswordStrength(password, nil))
	}

	fmt.Println("---------- Password with userInput-------------")
	// Test with user input, expected score 1
	DeterminePasswordStrength(passwords[1], []string{"Table"})
	utils.PrintJSON(DeterminePasswordStrength(passwords[1], []string{"Table"}))

	//for i := 0; i < 1000; i++ {
	for _, password := range passwords {
		fmt.Println("\n---------- GetScore:", password, " -------------")
		score, err := GetPasswordScore(password, nil)
		if err != nil {
			t.Fatal(err)
		}
		fmt.Println("Password:"******"\tScore:", score)
	}
	//}
	SetMinLength(11)
	SetMaxLength(15)
	fmt.Println("\n\n -- Added restriction min=11, max=15 --")
	for _, password := range passwords {
		fmt.Println("\n---------- GetScore:", password, " -------------")
		score, err := GetPasswordScore(password, nil)

		if err == nil {
			t.Fatal(err)
		}
		fmt.Println("Password:"******"\tScore:", score, "Error:", err.Error())
	}
}
Exemple #2
0
func TestCustomerRollback(t *testing.T) {
	customer1, _ := create2CustomersAndPerformSomeUpserts(t)
	utils.PrintJSON(customer1)
	log.Println("Version", customer1.GetVersion(), "FirstName", customer1.Person.FirstName)
	err := customer1.Rollback(customer1.GetVersion().Current - 2) // We need tp go 2 versions back to see the name change
	if err != nil {
		fmt.Println("Error: Could not roll back to previous version!")
		t.Fatal(err)
	}
	customer1, err = GetCustomerById(customer1.GetID(), nil)
	log.Println("Version", customer1.GetVersion(), "FirstName", customer1.Person.FirstName)

	// Due to Rollback, FirstName should be "Foo" again
	if customer1.Person.FirstName != "Foo" {
		fmt.Println("Error: Expected Name to be Foo but got " + customer1.Person.FirstName)
		t.Fail()
	}
}
Exemple #3
0
func TestCustomerChangeAddress(t *testing.T) {
	test_utils.DropAllCollections()
	customer, err := NewCustomer(MOCK_EMAIL, MOCK_PASSWORD, nil)
	if err != nil {
		t.Fatal(err)
	}

	addr := &address.Address{
		Person: &address.Person{
			Salutation: address.SalutationTypeMr,
			FirstName:  "Foo",
			MiddleName: "Bob",
			LastName:   "Bar",
		},
		Street:       "Holzweg",
		StreetNumber: "5",
		City:         "Bern",
		Country:      "CH",
		ZIP:          "1234",
	}
	log.Println("Original Address:")
	utils.PrintJSON(addr)
	id, err := customer.AddAddress(addr)
	log.Println("Added Address with id ", id)
	if err != nil {
		t.Fatal(err)
	}
	addressNew := &address.Address{
		Id: id, // Set id of address we want to replace
		Person: &address.Person{
			Salutation: address.SalutationTypeMr,
			FirstName:  "FooChanged",
			MiddleName: "Bob",
			LastName:   "Bar",
		},
		Street:       "Steinweg",
		StreetNumber: "5",
		City:         "Bern",
		Country:      "CH",
		ZIP:          "1234",
	}
	err = customer.ChangeAddress(addressNew)
	if err != nil {
		t.Fatal(err)
	}

	changedAddress, err := customer.GetAddressById(id)
	if err != nil {
		t.Fatal(err)
	}
	log.Println("Changed Address:")
	utils.PrintJSON(changedAddress)

	if changedAddress.Street != "Steinweg" {
		t.Fatal("Expected customer.Person.FirstName == \"FooChanged\" but got " + changedAddress.Street)
	}
	if changedAddress.Person.FirstName != "FooChanged" {
		t.Fatal("Expected changedAddress.Person.FirstName == \"FooChanged\" but got " + changedAddress.Person.FirstName)
	}

}
Exemple #4
0
func TestWatchListsManipulate(t *testing.T) {
	test_utils.DropAllCollections()
	customerID := unique.GetNewID()
	_, err := NewCustomerWatchListsFromCustomerID(customerID)
	if err != nil {
		t.Fatal(err)
	}
	cw, err := GetCustomerWatchListsByCustomerID(customerID)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	// Create List
	listA, err := cw.AddList("TypeX", "ListA", true, "me", utils.GetDateYYYY_MM_DD(), "My awesome list")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	// Add item to list
	err = cw.ListAddItem(listA.Id, "item1", 2)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	// Increase Quantity of item
	err = cw.ListAddItem(listA.Id, "item1", 3)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	// Add another item
	err = cw.ListAddItem(listA.Id, "item2", 2)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	item, err := cw.GetItem(listA.Id, "item1")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if item.Quantity != 5 {
		utils.PrintJSON(cw)
		t.Fatal("Wrong Quantity, expected 5")
	}
	// Reduce Quantity of item by 1
	err = cw.ListRemoveItem(listA.Id, "item2", 1)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	item, err = cw.GetItem(listA.Id, "item2")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if item.Quantity != 1 {
		t.Fatal("Wrong Quantity, expected 1")
	}
	// Remove last of item2
	err = cw.ListRemoveItem(listA.Id, "item2", 1)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}

	if len(listA.Items) != 1 {
		utils.PrintJSON(cw)
		t.Fatal("Expected 1 item in ListA")
	}
	newDescription := "new description"
	newName := "newName"
	// Edit list
	_, err = cw.EditList(listA.Id, newName, false, "", "", newDescription)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if listA.Name != newName || listA.Description != newDescription || listA.PublicURIHash != "" {
		utils.PrintJSON(cw)
		t.Fatal("EditList failed")
	}
	// Set item fulfilled
	cw.ListSetItemFulfilled(listA.Id, "item1", 2)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	item, err = cw.GetItem(listA.Id, "item1")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if item.QtyFulfilled != 2 {
		utils.PrintJSON(cw)
		t.Fatal("Expected QtyFulfilled == 2")
	}

	// Create second CustomerWatchLists and merge
	sessionID := unique.GetNewID()
	_, err = NewCustomerWatchListsFromSessionID(sessionID)
	if err != nil {
		t.Fatal(err)
	}
	cw2, err := GetCustomerWatchListsBySessionID(sessionID)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	listB, err := cw2.AddList("TypeX", "ListB", false, "recipient string", "targetDate string", "watchlist from session")
	if err != nil {
		t.Fatal(err)
	}
	err = cw2.ListAddItem(listB.Id, "item1b", 2)
	if err != nil {
		utils.PrintJSON(cw2)
		t.Fatal(err)
	}
	err = cw2.ListAddItem(listB.Id, "item1", 2)
	if err != nil {
		utils.PrintJSON(cw2)
		t.Fatal(err)
	}

	// Merge ListB from cw2 into ListA from cw
	err = MergeLists(cw2, listB.Id, cw, listA.Id)
	if err != nil {
		t.Fatal(err)
	}
	item, err = cw.GetItem(listA.Id, "item1")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if item.Quantity != 7 {
		utils.PrintJSON(cw)
		t.Fatal("Expected Quantity == 7")
	}
	item, err = cw2.GetItem(listB.Id, "item1b")
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}
	if item.Quantity != 2 {
		utils.PrintJSON(cw)
		t.Fatal("Expected Quantity == 2")
	}
	utils.PrintJSON(cw)

	// Test Getter
	cw, err = GetCustomerWatchListsByCustomerID(customerID)
	if err != nil {
		utils.PrintJSON(cw)
		t.Fatal(err)
	}

	// Test for non existant Id
	_, err = GetCustomerWatchListsByCustomerID("InvalidID")
	if err == nil {
		t.Fatal("Expected error not found", err)
	}

	watchList, err := cw2.EditList(listB.Id, "", true, "", "", "")
	if err != nil {
		t.Fatal("Edit List failed", err)
	}

	cw, err = GetCustomerWatchListsByURIHash(watchList.PublicURIHash)
	if err != nil {
		t.Fatal(err)
	}
	watchList, err = cw.GetListByURIHash(watchList.PublicURIHash)
	if err != nil {
		t.Fatal(err)
	}
	utils.PrintJSON(watchList)
}