forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthexternalbrowser_test.go
46 lines (39 loc) · 1.48 KB
/
authexternalbrowser_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
// Copyright (c) 2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"testing"
)
func TestGetTokenFromResponseFail(t *testing.T) {
response := "GET /?fakeToken=fakeEncodedSamlToken HTTP/1.1\r\n" +
"Host: localhost:54001\r\n" +
"Connection: keep-alive\r\n" +
"Upgrade-Insecure-Requests: 1\r\n" +
"User-Agent: userAgentStr\r\n" +
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n" +
"Referer: https://myaccount.snowflakecomputing.com/fed/login\r\n" +
"Accept-Encoding: gzip, deflate, br\r\n" +
"Accept-Language: en-US,en;q=0.9\r\n\r\n"
_, err := getTokenFromResponse(response)
if err == nil {
t.Errorf("Should have failed parsing the malformed response.")
}
}
func TestGetTokenFromResponse(t *testing.T) {
response := "GET /?token=GETtokenFromResponse HTTP/1.1\r\n" +
"Host: localhost:54001\r\n" +
"Connection: keep-alive\r\n" +
"Upgrade-Insecure-Requests: 1\r\n" +
"User-Agent: userAgentStr\r\n" +
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n" +
"Referer: https://myaccount.snowflakecomputing.com/fed/login\r\n" +
"Accept-Encoding: gzip, deflate, br\r\n" +
"Accept-Language: en-US,en;q=0.9\r\n\r\n"
expected := "GETtokenFromResponse"
token, err := getTokenFromResponse(response)
if err != nil {
t.Errorf("Failed to get the token. Err: %#v", err)
}
if token != expected {
t.Errorf("Expected: %s, found: %s", expected, token)
}
}