Skip to content

Commit

Permalink
feat(tests): cors testscript
Browse files Browse the repository at this point in the history
  • Loading branch information
fetsorn committed Dec 21, 2024
1 parent db47cb3 commit 889e7a7
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions testscript/testdata/http-cors.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# vi: set ft=conf

# FIXME: don't skip windows
[windows] skip 'curl makes github actions hang'

# convert crlf to lf on windows
[windows] dos2unix http1.txt http2.txt http3.txt goget.txt gitclone.txt

# start soft serve
exec soft serve &
# wait for server to start
waitforserver

# create user
soft user create user1 --key "$USER1_AUTHORIZED_KEY"

# create access token
soft token create --expires-in '1h' 'repo2'
cp stdout tokenfile
envfile TOKEN=tokenfile
soft token create --expires-in '1ns' 'repo2'
cp stdout etokenfile
envfile ETOKEN=etokenfile
usoft token create 'repo2'
cp stdout utokenfile
envfile UTOKEN=utokenfile

# push & create repo with some files, commits, tags...
mkdir ./repo2
git -c init.defaultBranch=master -C repo2 init
mkfile ./repo2/README.md '# Project\nfoo'
mkfile ./repo2/foo.png 'foo'
mkfile ./repo2/bar.png 'bar'
git -C repo2 remote add origin http://$TOKEN@localhost:$HTTP_PORT/repo2
git -C repo2 lfs install --local
git -C repo2 lfs track '*.png'
git -C repo2 add -A
git -C repo2 commit -m 'first'
git -C repo2 tag v0.1.0
git -C repo2 push origin HEAD
git -C repo2 push origin HEAD --tags

curl -v --request OPTIONS http://localhost:$HTTP_PORT/repo2.git/info/refs -H 'Origin: https://foo.example' -H 'Access-Control-Request-Method: GET'
stderr '.*Method Not Allowed.*'

# stop the server
stopserver

# allow cross-origin OPTIONS requests
env SOFT_SERVE_HTTP_CORS_ALLOWED_ORIGINS="https://foo.example"
env SOFT_SERVE_HTTP_CORS_ALLOWED_METHODS="GET,OPTIONS"
env SOFT_SERVE_HTTP_CORS_ALLOWED_HEADERS="Origin,Access-Control-Request-Method"

# restart soft serve
exec soft serve &
# wait for server to start
waitforserver

curl -v --request OPTIONS http://localhost:$HTTP_PORT/repo2.git/info/refs -H 'Origin: https://foo.example' -H 'Access-Control-Request-Method: GET'
stderr '.*200 OK.*'

# stop the server
[windows] stopserver
[windows] ! stderr .

0 comments on commit 889e7a7

Please sign in to comment.