예제 #1
0
func TestGetCred(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	flg := steward.Flag{ID: 1, Flag: "asdfasdf", Round: 5345, TeamID: 433,
		ServiceID: 353, Cred: "1:2"}

	err = steward.AddFlag(db.db, flg)

	flag, cred, err := steward.GetCred(db.db, flg.Round, flg.TeamID,
		flg.ServiceID)
	if err != nil {
		log.Fatalln("Get cred failed:", err)
	}

	if flag != flg.Flag || cred != flg.Cred {
		log.Fatalln("Gotten cred invalid")
	}
}
예제 #2
0
func getFlag(db *sql.DB, round int, team steward.Team,
	svc steward.Service) (state steward.ServiceState, err error) {

	flag, cred, err := steward.GetCred(db, round, team.ID, svc.ID)
	if err != nil {
		log.Println("Get cred failed:", err)
		state = steward.StatusCorrupt
		return
	}

	var logs string
	var serviceFlag string

	if team.UseNetbox {
		serviceFlag, logs, state, err = sshGet(team.Netbox,
			svc.CheckerPath, team.Vulnbox, svc.Port, cred)
	} else {
		serviceFlag, logs, state, err = get(svc.CheckerPath,
			team.Vulnbox, svc.Port, cred)
	}
	if err != nil {
		log.Println("Check service failed:", err)
		return
	}

	if flag != serviceFlag {
		state = steward.StatusCorrupt
	}

	if state != steward.StatusUP {
		log.Printf("Get flag, round %d, team %s, service %s: %s",
			round, team.Name, svc.Name, logs)
	}

	return
}