本文整理匯總了Golang中ibm-security-innovation/libsecurity-go/restful/common_restful.ConvertCommandToRequest函數的典型用法代碼示例。如果您正苦於以下問題:Golang ConvertCommandToRequest函數的具體用法?Golang ConvertCommandToRequest怎麽用?Golang ConvertCommandToRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ConvertCommandToRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestOneWayChallengeResponse
func TestOneWayChallengeResponse(t *testing.T) {
userName := usersName[0]
initAListOfUsers(t, usersName)
url := listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[verifyUserIdentityCommand]), usersPath, userName, verifyUserIdentityChallengeToken)
res := exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", cr.StringMessage{Str: getMessageStr})
var OcraData OcraData
err := json.Unmarshal([]byte(res), &OcraData)
if err != nil {
t.Errorf("Test fail: execute GET to '%v' expected to get ocra data but received: %v, error: %v",
url, res, err)
}
//Calculate the cleint OTP
otp, err := ocra.GenerateOCRAAdvance(OcraUserDataInfo.OcraSuite, secretCode,
OcraData.Counter, OcraData.ServerQuestion, OcraData.Password, OcraData.SessionId, OcraData.TimeStamp)
logger.Info.Println("The calculated OTP for ocra data:", res, "is:", otp)
if err != nil {
t.Errorf("Test fail: Try to generate OCRA with the following parameters: %v, error: %v", res, err)
}
OcraData.Otp = otp
data, _ := json.Marshal(OcraData)
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[verifyUserIdentityCommand]), usersPath, userName, verifyUserIdentityOtpToken)
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusOK, string(data), cr.Match{Match: true, Message: ""})
}
示例2: TestVerifyHotpCode
// 1. Check with match OTP code using HOTP/TOTP, verify the results
// 2. Check with not matched code using HOTP/TOTP, verify the results
func TestVerifyHotpCode(t *testing.T) {
var exp string
userName := usersName[0]
initAListOfUsers(t, usersName)
secret, _ := json.Marshal(cr.Secret{Secret: secretCode})
url := resourcePath + "/" + userName
okUrlJ := cr.Url{Url: fmt.Sprintf("%v/%v", ServicePath, userName)}
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusCreated, string(secret), okUrlJ) // TODO fix it
user, _ := otp.NewSimpleOtpUser([]byte(secretCode))
for i := 0; i < 2; i++ {
if i == 0 { // HOTP
exp, _ = user.BaseHotp.AtCount(user.BaseHotp.Count)
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[verifyUserCodeCommand]), UsersPath, userName, verifyHotpTypeParam)
} else {
exp, _ = user.BaseTotp.Now()
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[verifyUserCodeCommand]), UsersPath, userName, verifyTotpTypeParam)
}
secret, _ = json.Marshal(cr.Secret{Secret: exp})
exeCommandCheckRes(t, cr.POST_STR, url, http.StatusOK, string(secret), cr.Match{Match: true, Message: cr.NoMessageStr})
// The same code can't be used twice
exeCommandCheckRes(t, cr.POST_STR, url, http.StatusOK, string(secret), cr.Match{Match: false, Message: cr.NoMessageStr})
}
}
示例3: TestLogin
// Verify that a root login with appropriate password successfully
// Verify that a root login with wrong password fails
// Verify that an unknown user can't login
// Verify that logout works ok
func TestLogin(t *testing.T) {
loginRoot(t)
url := listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleAuthenticateCommand]), UserPath)
userLogin, _ := json.Marshal(userData{stc.RootUserName, []byte(string(rootPwd + "a"))})
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusMethodNotAllowed, string(userLogin), cr.Match{Match: false})
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleAuthenticateCommand]), UserPath)
userLogin, _ = json.Marshal(userData{stc.RootUserName + "1", []byte(string(rootPwd))})
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusNotFound, string(userLogin), cr.Match{Match: false})
}
示例4: TestVerifyResetPassword
// 2. Reset the user password
// 3. Check that the new password match only once
// 4. Update user password and verify that the new password matched
func TestVerifyResetPassword(t *testing.T) {
userName := usersName[0]
initAListOfUsers(t, usersName)
url := listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[resetUserPasswordCommand]), UsersPath, userName, ResetUserPwdPath)
secretStr := exeCommandCheckRes(t, cr.GET_STR, url, http.StatusCreated, getMessageStr, cr.StringMessage{Str: getMessageStr})
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[verifyUserPasswordCommand]), UsersPath, userName)
exeCommandCheckRes(t, cr.POST_STR, url, http.StatusOK, secretStr, cr.Match{Match: true, Message: cr.NoMessageStr})
secret1, _ := json.Marshal(secretData{secretCode})
exeCommandCheckRes(t, cr.POST_STR, url, http.StatusOK, string(secret1), cr.Match{Match: false, Message: cr.NoMessageStr})
}
示例5: TestSetUserBlockedState
// Set User blocked to true, false, true and verify the status
func TestSetUserBlockedState(t *testing.T) {
userName := usersName[0]
states := []bool{true, false, true}
initAListOfUsers(t, usersName)
for _, val := range states {
data, _ := json.Marshal(userState{val})
url := listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserBlockCommand]), UsersPath, userName, blockedStateToken)
okUrlJ := cr.Url{Url: fmt.Sprintf("%v/%v", ServicePath, userName)}
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusOK, string(data), okUrlJ) // fix the statusOK
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserBlockCommand]), UsersPath, userName, blockedStateToken)
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", userState{val})
}
}
示例6: TestAddGetDeleteItem
// Test the following functions: add/get/delete item to/from storage and get storage
// 1. Create a storage, and 2 key-value to the storage
// 2. Get the items and verify their values
// 3. Get the storage information and compare to the expected data
// 4. Delete the items and verify that it is not in the storage
// 5. Remove storage and verify that the list is empty
func TestAddGetDeleteItem(t *testing.T) {
keys := []string{"data1", "data2"}
values := []string{"value1", "value2"}
headerInfo := make(headerMapT)
headerInfo[secretIdParam] = secretCode
initState(t)
okUrlJ := cr.Url{Url: fmt.Sprintf("%v", ServicePath)}
for i, key := range keys {
url := itemPath
item, _ := json.Marshal(itemData{key, values[i]})
exeCommandCheckRes(t, cr.PATCH_STR, url, http.StatusCreated, string(item), baseHeaderInfo, okUrlJ)
headerInfo[keyIdParam] = key
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", headerInfo, itemValue{values[i]})
}
for i, key := range keys {
url := itemPath
headerInfo[keyIdParam] = key
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", headerInfo, itemValue{values[i]})
exeCommandCheckRes(t, cr.DELETE_STR, url, http.StatusNoContent, "", headerInfo, cr.EmptyStr)
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusNotFound, "", headerInfo, cr.Error{Code: http.StatusNotFound})
}
url := fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleStorageCommand]), resourcePath)
exeCommandCheckRes(t, cr.DELETE_STR, url, http.StatusNoContent, "", baseHeaderInfo, cr.EmptyStr)
}
示例7: setResource
// Initialize the UsersList to include resource
func setResource(t *testing.T, url string) {
for i, name := range resourcesName {
iUrl := url + EnServicePath
okUrlJ := cr.Url{Url: fmt.Sprintf("%v/%v", ResourceServicePath, name)}
specificUrl := iUrl + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUmResourceCommand]), name)
addDataVerifyResults(t, name, specificUrl, okUrlJ)
verifyLen(t, enPath, ResourcesPath, i+1)
}
}
示例8: TestUpdatePrivilege
// 1. As a root: Update the user privilege, verify the results
// 2. As a root: Update the root privilege, verify that it is not allowed
// 3. As the user: Update the user privilege, verify that it is not allowed
func TestUpdatePrivilege(t *testing.T) {
userName := usersName[0]
initAListOfUsers(t, usersName)
url := listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserPwdCommand]), UsersPath, userName, PrivilegePath)
okUrlJ := cr.Url{Url: fmt.Sprintf("%v/%v", ServicePath, userName)}
privilege, _ := json.Marshal(privilegePwd{Privilege: am.SuperUserPermission})
exeCommandCheckRes(t, cr.PATCH_STR, url, http.StatusCreated, string(privilege), okUrlJ)
url = listener + ServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUserPwdCommand]), UsersPath, stc.RootUserName, PrivilegePath)
okUrlJ = cr.Url{Url: fmt.Sprintf("%v/%v", ServicePath, stc.RootUserName)}
privilege, _ = json.Marshal(privilegePwd{Privilege: am.SuperUserPermission})
exeCommandCheckRes(t, cr.PATCH_STR, url, http.StatusBadRequest, string(privilege), cr.Error{Code: http.StatusBadRequest})
cookieStr, _ := app.GenerateToken(userName, am.UserPermission, clientIP, stRestful.SignKey)
cr.SetCookie(cookieStr)
exeCommandCheckRes(t, cr.PATCH_STR, url, http.StatusMethodNotAllowed, string(privilege), cr.Error{Code: http.StatusMethodNotAllowed})
}
示例9: setUm
// Initialize the UsersList to include all users from a given file
func setUm(t *testing.T, url string) {
for i, name := range usersName {
iUrl := url + EnServicePath
okUrlJ := cr.Url{Url: fmt.Sprintf("%v/%v", UsersServicePath, name)}
specificUrl := iUrl + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUmUserCommand]), name)
addDataVerifyResults(t, name, specificUrl, okUrlJ)
verifyLen(t, enPath, UsersPath, i+1+protectedEntityManagerLen)
}
}
示例10: TestAddRemoveUser
// Test the following:
// 1. The users list is empty
// 2. Add a new user, verify the response code and that there is only one user with the same content
// 4. Add a new user, verify the response code and that there are 2 users each with the extpected content
// 5. Remove the first user, verify the response code and that there is only one user, the second one
// 6. Remove the second user, verify the response code and that the user list is empty
func TestAddRemoveUser(t *testing.T) {
initState(t)
setUm(t, listener)
// remove users and verify that the number of users decrease
for i, name := range usersName {
url := listener + UsersServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUmCommand]), name)
exeCommandCheckRes(t, cr.DELETE_STR, url, http.StatusNoContent, "", cr.StringMessage{Str: ""})
verifyLen(t, enPath, UsersPath, len(usersName)-i+1)
}
}
示例11: TestAddRemoveResource
// Test the following:
// 1. The users list is empty
// 2. Add a new resource, verify the response code and that there is only one resource with the same content
// 4. Add a new resource, verify the response code and that there are 2 resource each with the extpected content
// 5. Remove the first resource, verify the response code and that there is only one resource, the second one
// 6. Remove the second resource, verify the response code and that the resource list is empty
func TestAddRemoveResource(t *testing.T) {
initState(t)
setResource(t, listener)
// remove resource and verify that the number of resource decrease
for i, name := range resourcesName {
url := listener + ResourceServicePath + fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handleUmCommand]), name)
exeCommandCheckRes(t, cr.DELETE_STR, url, http.StatusNoContent, "", cr.StringMessage{Str: ""})
verifyLen(t, enPath, ResourcesPath, len(resourcesName)-i-1)
}
}
示例12: Test_getAllPermissionsOfEntity
// Test estGetAllPermissionsOfEntity
// Add a set of permissions to resource for a given users list and verify that the respobse is as expected
func Test_getAllPermissionsOfEntity(t *testing.T) {
initState()
generateAcl()
baseUrl := fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[getAllPermissionsOfEntityCommand]), entityToken, userName1, resourceToken, resourceName1)
url := fmt.Sprintf("%v/%v", resourcePath, baseUrl)
data, _ := acl.GetUserPermissions(stRestful.UsersList, userName1, resourceName1)
res := []string{}
for p, _ := range data {
res = append(res, string(p))
}
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", res)
}
示例13: Test_getAllPermissions
// Test restGetAllPermissions
// Add a set of permissions to resource for a given users list and verify that the respobse is as expected
func Test_getAllPermissions(t *testing.T) {
initState()
_, a, _ := generateAcl()
baseUrl := fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[getAllPermissionCommand]), permissionsToken, resourceToken, resourceName1)
url := fmt.Sprintf("%v/%v", resourcePath, baseUrl)
data := a.GetAllPermissions()
res := []string{}
for p, _ := range data {
res = append(res, string(p))
}
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", res)
}
示例14: Test_getWhoUsesAResourcePermission
// Test restGetWhoUsesAResourcePermission
// Add a set of permissions to resource for a given users list and verify that the respobse is as expected
func Test_getWhoUsesAResourcePermission(t *testing.T) {
initState()
generateAcl()
permission := perAll
baseUrl := fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[getAllPermissionsOfEntityCommand]), resourceToken, resourceName1, permissionsToken, permission)
url := fmt.Sprintf("%v/%v", resourcePath, baseUrl)
data := acl.GetWhoUseAPermission(stRestful.UsersList, resourceName1, permission)
res := []string{}
for p, _ := range data {
res = append(res, p)
}
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", res)
}
示例15: Test_addCheckDeletePermission
// Add a permission to resource for a given user and verify that it have it
// Remove the permission for the resource from the user and verify it doesn't have it
func Test_addCheckDeletePermission(t *testing.T) {
initState()
strFmt := "%v/%v"
permission := perRead
baseUrl := fmt.Sprintf(cr.ConvertCommandToRequest(urlCommands[handlePermissionCommand]),
entityToken, userName1, resourceToken, resourceName1, permissionsToken, permission)
okUrlJ := cr.Url{Url: fmt.Sprintf(strFmt, ServicePath, baseUrl)}
url := fmt.Sprintf(strFmt, resourcePath, baseUrl)
exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusCreated, "", okUrlJ)
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusOK, "", cr.Match{Match: true, Message: ""})
exeCommandCheckRes(t, cr.DELETE_STR, url, http.StatusNoContent, "", cr.StringMessage{Str: ""})
str := fmt.Sprintf("Permission '%v' doesn't allowed", permission)
exeCommandCheckRes(t, cr.GET_STR, url, http.StatusNotFound, "", cr.Error{Code: 0, Message: str})
}