-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgoRunner_test.go
149 lines (126 loc) · 4.37 KB
/
goRunner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"testing"
)
var port string
//var baseUrl string
func TestXxx(*testing.T) {
verbose = true
done := make(chan bool)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
go func() {
<-sigs
done <- true
}()
go http.ListenAndServe(":9009", nil)
// http.HandleFunc("/main", Landing)
http.HandleFunc("/GetSession", ReturnSession)
http.HandleFunc("/reqapi/check/token", HandleToken)
http.HandleFunc("/reqapi/test/account/pass", HandleTicket)
http.HandleFunc("/reqapi/test/account/pass/", HandleTicket2)
//http.HandleFunc("/reqapi/test/shellVar", HandleShellVar)
// http.HandleFunc("/reqapi/test/upload", Landing)
http.HandleFunc("/general", General)
os.Setenv("shellVar", "test123")
clients = 1
baseUrl = "http://localhost:9009"
// ---------------------------------------------------------------------------------------------
// Init runner
runner := NewRunner("config.ini")
// ---------------------------------------------------------------------------------------------
// Start clients
trafficChannel := make(chan string)
// startTraffic(trafficChannel) //start reading on the channel
runner.StartClients(trafficChannel)
// ---------------------------------------------------------------------------------------------
// Output
runner.printSessionSummary()
PrintLogHeader(",", 1)
runner.PrintSessionLog() // ???
trafficChannel <- "1,2" //put work from the line we read to get nbDelimeters
close(trafficChannel)
// ---------------------------------------------------------------------------------------------
// Wait for clients to be done and exit
runner.Wait()
runner.Exit()
exitCode := 0
os.Exit(int(exitCode))
}
func ReturnSession(w http.ResponseWriter, r *http.Request) {
w.Header().Set("SESSIONVAR", "C1NC0d3M6Y0")
w.WriteHeader(200)
w.Write([]byte("TokenValue:=abcdefgh.localserver.com"))
io.WriteString(w, "Return SessionVariable, TokenValue=TOKEN, UserID in header")
}
//func Landing(w http.ResponseWriter, r *http.Request) {
// io.WriteString(w, "This is the Landing Page Body")
//}
func HandleToken(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
access_type := r.FormValue("access_type")
username, _, ok := r.BasicAuth()
authOk := ok == true && username == "ab4c4e00-d8a6-11e4-a96c-34fb509c20ca"
response := ""
switch access_type {
case "password":
response = "{\"access_token\":\"babd1aed-2e5b-40bb-a53f-d31d69d8571a\",\"refresh_token\":\"a77a8bfe-e9e6-4009-90f8-3e817685fed9\",\"token_type\":\"Carier\",\"expires_in\":3599,\"scope\":\"DEFAULT_SCOPE\"}"
case "refresh_token":
response = "{\"access_token\":\"babd1aed-2e5b-40bb-a53f-d31d69d8571a\",\"refresh_token\":\"a77a8bfe-e9e6-4009-90f8-3e817685fed9\",\"token_type\":\"Carier\",\"expires_in\":3599,\"scope\":\"DEFAULT_SCOPE\"}"
}
if !authOk {
w.WriteHeader(401)
}
fmt.Fprintf(w, "%v\n", response)
}
func HandleTicket(w http.ResponseWriter, r *http.Request) {
call_id := r.URL.Query().Get("call_id")
response := ""
if call_id == "" {
response = "{\"call_id\":\"[email protected]\"}"
} else {
response = "{\"pass\":\"451dbd05-67bd-4397-9557-ccfef789d8f0\"}"
}
fmt.Fprintf(w, "%v\n", response)
}
func HandleTicket2(w http.ResponseWriter, r *http.Request) {
pathArr := strings.SplitN(r.URL.RequestURI()[1:] /*trim the first slash*/, "/", -1)
fmt.Fprintf(w, "PATH=%v\n", pathArr[4])
}
//func HandleShellVar(w http.ResponseWriter, r *http.Request) {
// shellVar := r.URL.Query().Get("shellVar")
// fmt.Fprintf(w, "%v\n", shellVar)
//}
func General(w http.ResponseWriter, r *http.Request) {
testAnswer := r.URL.Query().Get("testAnswer") //add(2,3) = 5
actualAnswer := r.URL.Query().Get("actualAnswer") // 5
clientFile, _, err := r.FormFile("file")
if err == nil {
//optionally test file upload
var buff bytes.Buffer
fileSize, err := buff.ReadFrom(clientFile)
if err == nil {
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, "Success fileSize=%v\n", fileSize)
} else {
w.WriteHeader(http.StatusNotAcceptable)
fmt.Fprintf(w, "Failure fileSize=%v\n", fileSize)
}
return
}
if testAnswer == actualAnswer {
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, "Success %v %v\n", testAnswer, r.ContentLength)
} else {
w.WriteHeader(http.StatusNotAcceptable)
fmt.Fprintf(w, "Failure %v %v\n", testAnswer, r.ContentLength)
}
}