-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-c8xw-vjgf-94hr
Signed-off-by: pashakostohrys <pavel@codefresh.io>
- Loading branch information
1 parent
f978e04
commit e047efa
Showing
5 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package application | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/gorilla/websocket" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func reconnect(w http.ResponseWriter, r *http.Request) { | ||
var upgrader = websocket.Upgrader{} | ||
c, err := upgrader.Upgrade(w, r, nil) | ||
if err != nil { | ||
return | ||
} | ||
|
||
ts := terminalSession{wsConn: c} | ||
_, _ = ts.reconnect() | ||
} | ||
|
||
func TestReconnect(t *testing.T) { | ||
|
||
s := httptest.NewServer(http.HandlerFunc(reconnect)) | ||
defer s.Close() | ||
|
||
u := "ws" + strings.TrimPrefix(s.URL, "http") | ||
|
||
// Connect to the server | ||
ws, _, err := websocket.DefaultDialer.Dial(u, nil) | ||
assert.NoError(t, err) | ||
|
||
defer ws.Close() | ||
|
||
_, p, _ := ws.ReadMessage() | ||
|
||
var message TerminalMessage | ||
|
||
err = json.Unmarshal(p, &message) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, message.Data, ReconnectMessage) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters