Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use app password, change setup method #1957

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/api-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
coverage: none

- name: Setup BATS & httpie
run: sudo apt-get install -y bats httpie
run: sudo apt-get install -y httpie && npm install -g [email protected]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why use npm for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the Ubuntu package has like 1.1 in their repo slightly newer on new versions.
There is also no backports. For the basic stuff it will work but of course there are details that are different.

I can't work with that though latest is 1.8 but I didn't test that yet on my machine since it didn't land in manjaro as of now.

npm is one of the projects official distribution ways (not sure why), I checked the repo for alternative install methods after I noticed that Ubuntu is hanging behind.

And since npm is available in the action image I think this is the best way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will probably in the future also add a requires bats version X line to the bats files.

I have no time to debug issues because of bugs that were already fixed by the project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start like this then


### MySQL specific setup
- name: Setup mysql
Expand Down
71 changes: 40 additions & 31 deletions tests/api/feeds.bats
Original file line number Diff line number Diff line change
@@ -1,116 +1,125 @@
#!/usr/bin/env bats

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
setup_file(){
load "helpers/settings"

if test -f "tests/api/helpers/settings-override.bash"; then
load "helpers/settings-override"
fi

export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})')
}

teardown_file(){
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true
}

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
}

TESTSUITE="Feeds"

teardown() {
# delete all feeds
ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $ID_LIST; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
done

# delete all folders
ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $ID_LIST; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/folders/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null
done
}

@test "[$TESTSUITE] Read empty" {
run http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds

assert_output --partial "\"feeds\":[]"
assert_output --partial "\"starredCount\":0"
}

@test "[$TESTSUITE] Create new" {
# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].url')
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].url')

assert_output '"http://localhost:8090/Nextcloud.rss"'
}

@test "[$TESTSUITE] Create new inside folder" {
# create folder and store id
ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')

# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$ID | jq '.feeds | .[0].folderId')
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$ID | jq '.feeds | .[0].folderId')

# check if ID matches
assert_output "$ID"
}

@test "[$TESTSUITE] Delete one" {
ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')
ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')

run http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/feeds/$ID
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$ID

assert_output "[]"
}

@test "[$TESTSUITE] Move feed to different folder" {
# create folders and store ids
FIRST_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
SECCOND_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
FIRST_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
SECCOND_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')

FEEDID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FIRST_FOLDER_ID | grep -Po '"id":\K([0-9]+)')
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FIRST_FOLDER_ID | grep -Po '"id":\K([0-9]+)')

# move feed, returns nothing
http --ignore-stdin -b -a ${user}:${user} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=$SECCOND_FOLDER_ID
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=$SECCOND_FOLDER_ID

# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId')
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId')

# look for second folder id
assert_output "$SECCOND_FOLDER_ID"
}

@test "[$TESTSUITE] Move feed to root" {
# create folder and store id
FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')

FEEDID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)')
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)')

# move feed to "null", returns nothing
http --ignore-stdin -b -a ${user}:${user} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=null

# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId')
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId')

# new "folder" should be null
assert_output null
}

@test "[$TESTSUITE] Rename feed" {
# create feed and store id
FEEDID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')

# rename feed, returns nothing
http --ignore-stdin -b -a ${user}:${user} PUT ${BASE_URLv1}/feeds/$FEEDID/rename feedTitle="Great Title"
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/rename feedTitle="Great Title"

# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].title')
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].title')

# Check if title matches
assert_output '"Great Title"'
}

@test "[$TESTSUITE] Mark all items as read" {
# create feed and store id
FEEDID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')

ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

# get biggest item ID
max=${ID_LIST[0]}
Expand All @@ -119,10 +128,10 @@ teardown() {
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${user} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/)
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/)

# collect unread status
unread=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ')
unread=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ')

for n in "${unread[@]}" ; do
if $n
Expand Down
48 changes: 28 additions & 20 deletions tests/api/folders.bats
Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
#!/usr/bin/env bats

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
setup_file(){
load "helpers/settings"

if test -f "tests/api/helpers/settings-override.bash"; then
load "helpers/settings-override"
fi


export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})')
}

teardown_file(){
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true
}

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
}

TESTSUITE="Folders"

teardown() {
# delete all feeds
FEED_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
FEED_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $FEED_IDS; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
done

# delete all folders
FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $FOLDER_IDS; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/folders/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null
done
}

@test "[$TESTSUITE] Read empty" {
run http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders

assert_output --partial "\"folders\":[]"
}

@test "[$TESTSUITE] Create new" {
run http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER}
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER}

assert_output --partial "\"name\":\"news-${BATS_SUITE_TEST_NUMBER}\","
}

@test "[$TESTSUITE] Delete folder" {
ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')

run http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/folders/$ID
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$ID

assert_output "[]"
}

@test "[$TESTSUITE] Rename folder" {
ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')

# Rename folder
http --ignore-stdin -b -a ${user}:${user} PUT ${BASE_URLv1}/folders/$ID name=rename-${BATS_SUITE_TEST_NUMBER}
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/folders/$ID name=rename-${BATS_SUITE_TEST_NUMBER}

run http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders

assert_output --partial "\"name\":\"rename-${BATS_SUITE_TEST_NUMBER}\","
}

@test "[$TESTSUITE] Mark all items as read" {
# create folder and feed in folder
FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
FEED_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)')
FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)')
FEED_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)')

ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

# get biggest item ID
max=${ID_LIST[0]}
Expand All @@ -72,10 +80,10 @@ teardown() {
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${user} PUT ${BASE_URLv1}/folders/$FOLDER_ID/read newestItemId="$max" 2>&1| grep HTTP/)
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/folders/$FOLDER_ID/read newestItemId="$max" 2>&1| grep HTTP/)

# collect unread status
unread=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ')
unread=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ')

for n in "${unread[@]}" ; do
if $n
Expand Down
9 changes: 5 additions & 4 deletions tests/api/helpers/settings.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
user=admin
NC_FEED="http://localhost:8090/Nextcloud.rss"
HEISE_FEED="http://localhost:8090/heise.xml"
BASE_URLv1="http://localhost:8080/index.php/apps/news/api/v1-2"
export user=admin
export NC_FEED="http://localhost:8090/Nextcloud.rss"
export HEISE_FEED="http://localhost:8090/heise.xml"
export BASE_URLv1="http://localhost:8080/index.php/apps/news/api/v1-2"
export NC_HOST="http://localhost:8080"
40 changes: 25 additions & 15 deletions tests/api/items.bats
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
#!/usr/bin/env bats

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
setup_file(){
load "helpers/settings"

if test -f "tests/api/helpers/settings-override.bash"; then
load "helpers/settings-override"
fi

export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})')
}

teardown_file(){
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true
}

setup() {
load "../test_helper/bats-support/load"
load "../test_helper/bats-assert/load"
}


TESTSUITE="Items"

teardown() {
# delete all feeds
FEED_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
FEED_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $FEED_IDS; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
done

# delete all folders
FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
for i in $FOLDER_IDS; do
http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/folders/$i > /dev/null
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null
done
}

@test "[$TESTSUITE] Read empty" {
run http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items
run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items

assert_output --partial "\"items\":[]"
}

@test "[$TESTSUITE] Read 5" {
http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED

ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items batchSize=5 | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items batchSize=5 | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

output=${#ID_LIST[@]}

Expand All @@ -45,8 +55,8 @@ teardown() {
# TODO GET /items has more options that could be tested.

@test "[$TESTSUITE] Check updated" {
FEEDID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')
ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)')
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

# get biggest item ID
max=${ID_LIST[0]}
Expand All @@ -57,10 +67,10 @@ teardown() {
SYNC_TIME=$(date +%s)

# mark all items of feed as read, returns nothing (other client marks items as read)
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${user} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/)
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/)

# client 2 checks for updates since last sync
UPDATED_ITEMS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/items/updated id=$FEEDID lastModified=$SYNC_TIME | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
UPDATED_ITEMS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items/updated id=$FEEDID lastModified=$SYNC_TIME | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

assert_equal ${#ID_LIST[@]} ${#UPDATED_ITEMS[@]}
}
2 changes: 1 addition & 1 deletion tests/test_helper/feeds/Nextcloud.rss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<channel>
<title>Nextcloud</title>
<atom:link href="https://nextcloud.com/feed/" rel="self" type="application/rss+xml" />
<atom:link href="http://localhost:8090/Nextcloud.rss" rel="self" type="application/rss+xml" />
<link>https://nextcloud.com/</link>
<description></description>
<lastBuildDate>Tue, 16 Aug 2022 10:17:13 +0000</lastBuildDate>
Expand Down
Loading