#!/bin/sh # The atom page serves recent history as a feed. The checks read the content # type, count the entries against the max-atom-items cap, and hand the feed # to xmllint where installed, a far stricter reader than any grep here. test_description='Check the atom feed' . ./setup.sh test_expect_success 'generate foo/atom' ' cgit_url "foo/atom" >tmp ' test_expect_success 'the response is an atom feed' ' head -n 1 tmp | grep "Status: 200 OK" && sed "/^$/q" tmp | grep "Content-Type: application/atom+xml" && strip_headers feed && grep "" feed && grep "foo, branch master" feed ' test_expect_success 'every commit of a small repository is an entry' ' test $(grep -c "" feed) -eq 5 && grep "commit 1" feed && grep "commit 5" feed ' test_expect_success 'ten entries is the default ceiling' ' cgit_url "bar/atom" >tmp && strip_headers feed && test $(grep -c "" feed) -eq 10 && grep "commit 50" feed && ! grep "commit 40" feed ' test_expect_success 'max-atom-items overrides the ceiling' ' cgitrc_repo atomrc bar max-atom-items=3 && cgit_rc atomrc "url=bar/atom" >tmp && strip_headers feed && test $(grep -c "" feed) -eq 3 ' test_lazy_prereq XMLLINT 'command -v xmllint' test_expect_success XMLLINT 'the feed is well-formed xml' ' cgit_url "foo/atom" >tmp && strip_headers feed && xmllint --noout feed ' # A path starting with a colon would reach git as pathspec magic, which the # log refuses as well. test_expect_success 'a path with pathspec magic is refused' ' cgit_url "foo/atom/%3A%28icase%29FILE-1" >tmp && grep "^Status: 400" tmp && cgit_url "foo/atom/file-1" >tmp && grep "^Status: 200" tmp ' test_expect_success 'enable-plain-email=0 leaves the address out of the feed' ' cgitrc_copy plainrc enable-plain-email=0 && cgit_ok plainrc "url=foo/atom" >tmp && grep "A U Thor" tmp && ! grep "" tmp && ! grep "author@example.com" tmp ' test_expect_success 'the feed link encodes the repository and the branch' ' cgitrc_copy feedrc && CGIT_CONFIG="$PWD/feedrc" HTTP_HOST=example.org QUERY_STRING="url=foo%2Bbar/log/&h=1%2B2" cgit >tmp && grep "title=.Atom feed. href=.http://example.org/foo%2Bbar/atom/?h=1%2B2." tmp ' # A reader may subscribe before the first push, and the page every other view # of an empty repository falls back to is no feed it can read. test_expect_success 'an empty repository answers with a feed of no entries' ' git init -q --bare repos/empty.git && cgitrc_repo emptyrc empty "repo.path=$PWD/repos/empty.git" && cgit_rc emptyrc "url=empty/atom" >tmp && head -n 1 tmp | grep "Status: 200 OK" && sed "/^$/q" tmp | grep "Content-Type: application/atom+xml" && strip_headers feed && grep "empty" feed && grep "" feed && ! grep "" feed && grep "" feed ' test_expect_success XMLLINT 'the empty feed is well-formed xml' ' xmllint --noout feed ' # Markup in a message has to be escaped, and a control byte, a byte that is # no UTF-8 and the two noncharacters XML forbids each make a reader reject # the whole feed, so they are replaced. Valid UTF-8 is kept as it is. git # commit would rewrite the stray bytes as Latin-1, so the object is written # by hand. A commit has its stray bytes replaced as it is parsed, so the # description, which comes from the config as it was written, carries one to # the feed. test_expect_success 'set up a commit holding what XML cannot carry' ' test_create_repo repos/odd && ( cd repos/odd && tree=$(git mktree commit && printf "author Odd & Name \003 \375 \357\277\276 X 1112354055 +0200\n" >>commit && printf "committer C O Mitter 1112354055 +0200\n\n" >>commit && printf "a < b & c \001 \377 \357\277\276 \303\251\n\nbody > x & \002 \376 \357\277\277\n" >>commit && oid=$(git hash-object -t commit -w commit) && git update-ref HEAD "$oid" && git cat-file commit HEAD >actual && test_cmp commit actual ) && cgitrc_repo oddrc odd "repo.desc=$(printf "d < e & \004 \374 \357\277\277 \303\251")" ' test_expect_success 'the feed escapes markup and replaces what XML forbids' ' cgit_ok oddrc "url=odd/atom" >tmp && strip_headers oddfeed && printf "d < e & ? ? ? \303\251\n" >expect && grep "^" oddfeed >actual && test_cmp expect actual && printf "a < b & c ? ? ? \303\251\n" >expect && grep "^a " oddfeed >actual && test_cmp expect actual && printf "<content type=\047text\047>body > x & ? ? ?\n" >expect && grep "^<content " oddfeed >actual && test_cmp expect actual && printf "<name>Odd & Name ? ? ? X</name>\n" >expect && grep "^<name>" oddfeed >actual && test_cmp expect actual ' test_expect_success XMLLINT 'that feed is well-formed xml' ' xmllint --noout oddfeed ' test_done