File: client_inquire_context_test.go

package info (click to toggle)
gitlab-shell 14.35.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,652 kB
  • sloc: ruby: 1,129; makefile: 583; sql: 391; sh: 384
file content (79 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download
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
// Copyright 2013-2015 Apcera Inc. All rights reserved.

// +build clienttest

package test

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"regexp"
	"strings"
	"testing"
)

func verifyInquireContextResult(t *testing.T, result string, regexps []string) {
	rr := strings.Split(result, " ")
	if len(rr) != len(regexps) {
		t.Fatalf("got %v fragments, expected %v (%s)", len(rr), len(regexps), result)
	}

	for i, r := range rr {
		rx := regexp.MustCompile(regexps[i])
		if !rx.MatchString(r) {
			t.Errorf("%s does not match %s", r, regexps[i])
		}
	}
}

func TestClientInquireContext(t *testing.T) {
	ctx, r := initClientContext(t, "GET", "/inquire_context/", nil)
	defer ctx.Release()

	srcName, targetName, lifetimeRec, mechType, ctxFlags,
		locallyInitiated, open, err := ctx.InquireContext()
	if err != nil {
		t.Fatal(err)
	}
	defer srcName.Release()
	defer targetName.Release()

	verifyInquireContextResult(t,
		fmt.Sprintf("%q %q %v %q %x %v %v",
			srcName, targetName, lifetimeRec, mechType.DebugString(), ctxFlags,
			locallyInitiated, open),
		[]string{
			`"[a-zA-Z_-]+@[[:graph:]]+"`,
			`"HTTP/[[:graph:]]+@[[:graph:]]+"`,
			`[0-9a-z]+`,
			`[A-Z]+`,
			"1b0",
			"true",
			"true",
		})

	resp, err := http.DefaultClient.Do(r)
	if err != nil {
		t.Fatal(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		t.Fatalf("Expected status 200, got %v", resp.StatusCode)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Fatal(err)
	}
	verifyInquireContextResult(t, string(body),
		[]string{
			`"[a-zA-Z_-]+@[[:graph:]]+"`,
			`"HTTP/[[:graph:]]+@[[:graph:]]+"`,
			`[0-9a-z]+`,
			`[A-Z]+`,
			"130",
			"false",
			"true",
		})
}