File: wwwauthenticate_test.go

package info (click to toggle)
golang-github-containers-image 5.28.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,104 kB
  • sloc: sh: 194; makefile: 73
file content (45 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (5)
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
package docker

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

// This is just a smoke test for the common expected header formats,
// by no means comprehensive.
func TestParseValueAndParams(t *testing.T) {
	for _, c := range []struct {
		input  string
		scope  string
		params map[string]string
	}{
		{
			`Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/busybox:pull"`,
			"bearer",
			map[string]string{
				"realm":   "https://auth.docker.io/token",
				"service": "registry.docker.io",
				"scope":   "repository:library/busybox:pull",
			},
		},
		{
			`Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/busybox:pull,push"`,
			"bearer",
			map[string]string{
				"realm":   "https://auth.docker.io/token",
				"service": "registry.docker.io",
				"scope":   "repository:library/busybox:pull,push",
			},
		},
		{
			`Bearer realm="http://127.0.0.1:5000/openshift/token"`,
			"bearer",
			map[string]string{"realm": "http://127.0.0.1:5000/openshift/token"},
		},
	} {
		scope, params := parseValueAndParams(c.input)
		assert.Equal(t, c.scope, scope, c.input)
		assert.Equal(t, c.params, params, c.input)
	}
}