add test for FilterTargets()

This commit is contained in:
Wenkai Yin 2016-06-13 08:42:11 +08:00
parent 3bc41cc6d3
commit e5fe595f62
2 changed files with 15 additions and 2 deletions

View File

@ -132,8 +132,9 @@ func (t *TargetAPI) Get() {
t.CustomAbort(http.StatusNotFound, http.StatusText(http.StatusNotFound))
}
// the reason why the password is returned is that when user just wants to
// modify other fields of target he does not need to input the password again
// The reason why the password is returned is that when user just wants to
// modify other fields of target he does not need to input the password again.
// The security issue can be fixed by enable https.
if len(target.Password) != 0 {
pwd, err := utils.ReversibleDecrypt(target.Password)
if err != nil {

View File

@ -731,6 +731,7 @@ var targetID, policyID, policyID2, policyID3, jobID, jobID2, jobID3 int64
func TestAddRepTarget(t *testing.T) {
target := models.RepTarget{
Name: "test",
URL: "127.0.0.1:5000",
Username: "admin",
Password: "admin",
@ -838,6 +839,17 @@ func TestGetAllRepTargets(t *testing.T) {
}
}
func TestFilterRepTargets(t *testing.T) {
targets, err := FilterRepTargets("test")
if err != nil {
t.Fatalf("failed to get all targets: %v", err)
}
if len(targets) == 0 {
t.Errorf("unexpected num of targets: %d, expected: %d", len(targets), 1)
}
}
func TestAddRepPolicy(t *testing.T) {
policy := models.RepPolicy{
ProjectID: 1,