File: main_test.go

package info (click to toggle)
git-credential-oauth 0.17.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: makefile: 7
file content (46 lines) | stat: -rw-r--r-- 1,042 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
package main

import (
	"os"
	"strings"
	"testing"
)

func TestConfig(t *testing.T) {
	for key, c := range configByHost {
		if key == "android.googlesource.com" || key == "gist.github.com" {
			continue
		}
		if !strings.Contains(c.Endpoint.AuthURL, key) {
			t.Errorf("bad auth url for key %s: %s", key, c.Endpoint.AuthURL)
		}
		if !strings.Contains(c.Endpoint.TokenURL, key) {
			t.Errorf("bad token url for key %s: %s", key, c.Endpoint.TokenURL)
		}
		if c.Endpoint.DeviceAuthURL != "" && !strings.Contains(c.Endpoint.DeviceAuthURL, key) {
			t.Errorf("bad device auth url for key %s: %s", key, c.Endpoint.DeviceAuthURL)
		}
	}
}

func TestQR(t *testing.T) {
	msg := os.Getenv("QR_MSG")
	if msg == "" {
		t.Skip("no QR_MSG set, skipping")
	}
	if err := writeQRCode(os.Stdout, msg); err != nil {
		t.Fatal(err)
	}
}

func FuzzParse(f *testing.F) {
	f.Add("key=value")
	f.Add("key=")
	f.Add("==")
	f.Add("\n\n\n")
	f.Add("key=value=long")
	f.Add("wwwauth[]=value1\nwwwauth[]=value2")
	f.Fuzz(func(_ *testing.T, s string) {
		parse(s)
	})
}