http-cors.txtar

 1# vi: set ft=conf
 2
 3# FIXME: don't skip windows
 4[windows] skip 'curl makes github actions hang'
 5
 6# convert crlf to lf on windows
 7[windows] dos2unix http1.txt http2.txt http3.txt goget.txt gitclone.txt
 8
 9# start soft serve
10exec soft serve &
11# wait for SSH server to start
12ensureserverrunning SSH_PORT
13
14# create user
15soft user create user1 --key "$USER1_AUTHORIZED_KEY"
16
17# create access token
18soft token create --expires-in '1h' 'repo2'
19cp stdout tokenfile
20envfile TOKEN=tokenfile
21soft token create --expires-in '1ns' 'repo2'
22cp stdout etokenfile
23envfile ETOKEN=etokenfile
24usoft token create 'repo2'
25cp stdout utokenfile
26envfile UTOKEN=utokenfile
27
28# push & create repo with some files, commits, tags...
29mkdir ./repo2
30git -c init.defaultBranch=master -C repo2 init
31mkfile ./repo2/README.md '# Project\nfoo'
32mkfile ./repo2/foo.png 'foo'
33mkfile ./repo2/bar.png 'bar'
34git -C repo2 remote add origin http://$TOKEN@localhost:$HTTP_PORT/repo2
35git -C repo2 lfs install --local
36git -C repo2 lfs track '*.png'
37git -C repo2 add -A
38git -C repo2 commit -m 'first'
39git -C repo2 tag v0.1.0
40git -C repo2 push origin HEAD
41git -C repo2 push origin HEAD --tags
42
43curl -v --request OPTIONS http://localhost:$HTTP_PORT/repo2.git/info/refs -H 'Origin: https://foo.example' -H 'Access-Control-Request-Method: GET'
44stderr '.*Method Not Allowed.*'
45
46# stop the server
47stopserver
48
49# allow cross-origin OPTIONS requests
50env SOFT_SERVE_HTTP_CORS_ALLOWED_ORIGINS="https://foo.example"
51env SOFT_SERVE_HTTP_CORS_ALLOWED_METHODS="GET,OPTIONS"
52env SOFT_SERVE_HTTP_CORS_ALLOWED_HEADERS="Origin,Access-Control-Request-Method"
53
54# restart soft serve
55exec soft serve &
56# wait for SSH server to start
57ensureserverrunning SSH_PORT
58
59curl -v --request OPTIONS http://localhost:$HTTP_PORT/repo2.git/info/refs -H 'Origin: https://foo.example' -H 'Access-Control-Request-Method: GET'
60stderr '.*200 OK.*'
61
62# stop the server
63[windows] stopserver
64[windows] ! stderr .