// Check that an update key is working as expected
func TestVerifyUpdateKey(t *testing.T) {
	userName := usersName[0]
	newSecret := secretCode + "aa"

	initAListOfUsers(t, usersName)
	url := listener + servicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserUpdateCommand]), usersPath, userName, keyToken)
	okURLJ := cr.URL{URL: fmt.Sprintf("%v/%v", servicePath, userName)}
	secret, _ := json.Marshal(cr.Secret{Secret: newSecret})
	exeCommandCheckRes(t, cr.HTTPPatchStr, url, http.StatusCreated, string(secret), okURLJ)

	OcraData, _ := ocra.NewOcraUser([]byte(newSecret), internalOcraSuite)
	url = resourcePath + "/" + userName
	exeCommandCheckRes(t, cr.HTTPGetStr, url, http.StatusOK, "", OcraData)
}
func GenerateUserData(el *EntityManager, usersName []string, secret []byte, salt []byte) {
	el.AddUser(usersName[0])
	el.AddResource("r" + usersName[0])
	amData, _ := am.NewUserAm(am.SuperUserPermission, secret, salt, false)
	el.AddPropertyToEntity(usersName[0], defs.AmPropertyName, amData)
	otpData, _ := otp.NewSimpleOtpUser(secret, false)
	el.AddPropertyToEntity(usersName[0], defs.OtpPropertyName, otpData)
	pwdData, _ := password.NewUserPwd(secret, salt, false)
	el.AddPropertyToEntity(usersName[0], defs.PwdPropertyName, pwdData)
	ocraData, _ := ocra.NewOcraUser([]byte("ABCD1234"), "OCRA-1:HOTP-SHA512-8:C-QH08-T1M-S064-PSHA256")
	el.AddPropertyToEntity(usersName[0], defs.OcraPropertyName, ocraData)

	el.AddUser(usersName[1])
	el.AddPropertyToEntity(usersName[1], defs.OtpPropertyName, otpData)
}
// 2. Check that an update ocraSuite is working as expected
func TestVerifyUpdateOcraSuite(t *testing.T) {
	userName := usersName[0]
	newOcra := "OCRA-1:HOTP-SHA512-8:C-QH08-T1M-S064-PSHA256"

	initAListOfUsers(t, usersName)

	url := listener + servicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserUpdateCommand]), usersPath, userName, ocraSuiteToken)
	okURLJ := cr.URL{URL: fmt.Sprintf("%v/%v", servicePath, userName)}
	str, _ := json.Marshal(cr.StringMessage{Str: newOcra})
	exeCommandCheckRes(t, cr.HTTPPatchStr, url, http.StatusCreated, string(str), okURLJ)

	OcraData, _ := ocra.NewOcraUser([]byte(secretCode), newOcra)
	url = resourcePath + "/" + userName
	exeCommandCheckRes(t, cr.HTTPGetStr, url, http.StatusOK, "", OcraData)
}
func (o OcraRestful) restAddOcra(request *restful.Request, response *restful.Response) {
	var ocraData ocraUserData
	name := request.PathParameter(userIDParam)

	err := request.ReadEntity(&ocraData)
	if err != nil {
		o.setError(response, http.StatusBadRequest, err)
		return
	}
	data, err := ocra.NewOcraUser([]byte(ocraData.Secret), ocraData.OcraSuite)
	if err != nil {
		o.setError(response, http.StatusBadRequest, err)
		return
	}
	err = o.st.UsersList.AddPropertyToEntity(name, defs.OcraPropertyName, data)
	if err != nil {
		o.setError(response, http.StatusNotFound, err)
		return
	}
	response.WriteHeaderAndEntity(http.StatusCreated, o.getURLPath(request, name))
}
func Test_AddCheckRemoveOcraUserProperty(t *testing.T) {
	moduleData, _ := ocra.NewOcraUser([]byte("12345678"), "OCRA-1:HOTP-SHA512-8:C-QH08-T1M-S064-PSHA256")

	testAddCheckRemoveUserProperty(t, defs.OcraPropertyName, moduleData)
}