GitLabgitlab-org
cli
main
1//go:build !integration
3package oauth2
5import (
6 "strings"
7 "testing"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11)
13func TestValidateClientID(t *testing.T) {
14 t.Parallel()
16 validID := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
18 t.Run("valid 64 hex characters", func(t *testing.T) {
19 t.Parallel()
20 require.NoError(t, ValidateClientID(validID))
21 })
23 t.Run("valid with uppercase hex", func(t *testing.T) {
24 t.Parallel()
25 require.NoError(t, ValidateClientID(strings.ToUpper(validID)))
26 })
28 t.Run("valid with surrounding whitespace", func(t *testing.T) {
29 t.Parallel()
30 require.NoError(t, ValidateClientID(" "+validID+" \n"))
31 })
33 t.Run("empty value", func(t *testing.T) {
34 t.Parallel()
35 err := ValidateClientID("")
36 require.Error(t, err)
37 assert.Equal(t, "OAuth application ID cannot be empty", err.Error())
38 })
40 t.Run("whitespace only", func(t *testing.T) {
41 t.Parallel()
42 err := ValidateClientID(" \t\n")
43 require.Error(t, err)
44 assert.Equal(t, "OAuth application ID cannot be empty", err.Error())
45 })
47 t.Run("personal access token prefix glpat-", func(t *testing.T) {
48 t.Parallel()
49 err := ValidateClientID("glpat-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
50 require.Error(t, err)
51 assert.Equal(t, "value is a personal access token (glpat-), not an OAuth application ID", err.Error())
52 })
54 t.Run("uppercase personal access token prefix GLPAT-", func(t *testing.T) {
55 t.Parallel()
56 err := ValidateClientID("GLPAT-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
57 require.Error(t, err)
58 assert.Equal(t, "value is a personal access token (glpat-), not an OAuth application ID", err.Error())
59 })
61 t.Run("application secret prefix gloas-", func(t *testing.T) {
62 t.Parallel()
63 err := ValidateClientID("gloas-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
64 require.Error(t, err)
65 assert.Equal(t, "value is an OAuth application secret (gloas-), not the Application ID (glab is a public client and does not use a secret)", err.Error())
66 })
68 t.Run("mixed case application secret prefix Gloas-", func(t *testing.T) {
69 t.Parallel()
70 err := ValidateClientID("Gloas-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
71 require.Error(t, err)
72 assert.Equal(t, "value is an OAuth application secret (gloas-), not the Application ID (glab is a public client and does not use a secret)", err.Error())
73 })
75 t.Run("generic gitlab token prefix", func(t *testing.T) {
76 t.Parallel()
77 err := ValidateClientID("glcbt-abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345")
78 require.Error(t, err)
79 assert.Equal(t, "value appears to be a GitLab token, not an OAuth application ID", err.Error())
80 })
82 t.Run("too short", func(t *testing.T) {
83 t.Parallel()
84 err := ValidateClientID("12345")
85 require.Error(t, err)
86 assert.Equal(t, "OAuth application ID must be 64 hexadecimal characters", err.Error())
87 })
89 t.Run("too long", func(t *testing.T) {
90 t.Parallel()
91 err := ValidateClientID(validID + "ab")
92 require.Error(t, err)
93 assert.Equal(t, "OAuth application ID must be 64 hexadecimal characters", err.Error())
94 })
96 t.Run("non-hex characters", func(t *testing.T) {
97 t.Parallel()
98 invalid := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdeg"
99 err := ValidateClientID(invalid)
100 require.Error(t, err)
101 assert.Equal(t, "OAuth application ID must be 64 hexadecimal characters", err.Error())
102 })
103}
105func TestValidateTokenPrefix(t *testing.T) {
106 t.Parallel()
108 t.Run("valid arbitrary client id without token prefix", func(t *testing.T) {
109 t.Parallel()
110 require.NoError(t, validateTokenPrefix("custom-client-id-12345"))
111 })
113 t.Run("allows custom client id starting with gl", func(t *testing.T) {
114 t.Parallel()
115 require.NoError(t, validateTokenPrefix("gitlab-custom-client-id"))
116 require.NoError(t, validateTokenPrefix("global-client-id"))
117 require.NoError(t, validateTokenPrefix("gl-custom-id"))
118 })
120 t.Run("empty value", func(t *testing.T) {
121 t.Parallel()
122 require.NoError(t, validateTokenPrefix(""))
123 })
125 t.Run("whitespace only", func(t *testing.T) {
126 t.Parallel()
127 require.NoError(t, validateTokenPrefix(" \t\n"))
128 })
130 t.Run("personal access token prefix glpat-", func(t *testing.T) {
131 t.Parallel()
132 err := validateTokenPrefix("glpat-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
133 require.Error(t, err)
134 assert.Equal(t, "value is a personal access token (glpat-), not an OAuth application ID", err.Error())
135 })
137 t.Run("case insensitive personal access token prefix", func(t *testing.T) {
138 t.Parallel()
139 err := validateTokenPrefix("GLPAT-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
140 require.Error(t, err)
141 assert.Equal(t, "value is a personal access token (glpat-), not an OAuth application ID", err.Error())
142 })
144 t.Run("application secret prefix gloas-", func(t *testing.T) {
145 t.Parallel()
146 err := validateTokenPrefix("gloas-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
147 require.Error(t, err)
148 assert.Equal(t, "value is an OAuth application secret (gloas-), not the Application ID (glab is a public client and does not use a secret)", err.Error())
149 })
151 t.Run("case insensitive application secret prefix", func(t *testing.T) {
152 t.Parallel()
153 err := validateTokenPrefix("Gloas-abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456")
154 require.Error(t, err)
155 assert.Equal(t, "value is an OAuth application secret (gloas-), not the Application ID (glab is a public client and does not use a secret)", err.Error())
156 })
158 t.Run("generic gitlab token prefix", func(t *testing.T) {
159 t.Parallel()
160 err := validateTokenPrefix("glcbt-abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345")
161 require.Error(t, err)
162 assert.Equal(t, "value appears to be a GitLab token, not an OAuth application ID", err.Error())
163 })
165 t.Run("case insensitive generic token prefix", func(t *testing.T) {
166 t.Parallel()
167 err := validateTokenPrefix("GLCBT-abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345")
168 require.Error(t, err)
169 assert.Equal(t, "value appears to be a GitLab token, not an OAuth application ID", err.Error())
170 })
171}
Diagnostics6 git calls · 39 ms
CallStatusSizeTime039 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB · hit8 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=8 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:0200468 B · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=468 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=c498f09dbd0cebbc59f9eff3b3ef8be66186fac6 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=468 git.pkt.payload.max=441 git.sideband.band1.bytes=441 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=441 git.pack.trailer=6420a98b3b2e923a6b61c550c00de326d620e479Open pack map
fetch200890 B · hit27 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=27 git.response.bytes=890 git.response.cache=HIT git.response.duration_ms=27 git.fetch.wants=25a34ee231be5f2d06f919f661421f7ee7978f3e git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=890 git.pkt.payload.max=863 git.sideband.band1.bytes=863 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e242612e18cf56
- Request
- f913b84c…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format