2018-08-25 14:53:14 -04:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
miniflux "miniflux.app/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWithWrongCredentials(t *testing.T) {
|
|
|
|
client := miniflux.New(testBaseURL, "invalid", "invalid")
|
|
|
|
_, err := client.Users()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Using bad credentials should raise an error`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrNotAuthorized {
|
|
|
|
t.Fatal(`A "Not Authorized" error should be raised`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetCurrentLoggedUser(t *testing.T) {
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.Me()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
t.Fatalf(`Invalid userID, got %q`, user.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Username != testAdminUsername {
|
|
|
|
t.Fatalf(`Invalid username, got %q`, user.Username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUsers(t *testing.T) {
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
users, err := client.Users()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(users) == 0 {
|
|
|
|
t.Fatal("The list of users is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if users[0].ID == 0 {
|
|
|
|
t.Fatalf(`Invalid userID, got "%v"`, users[0].ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if users[0].Username != testAdminUsername {
|
|
|
|
t.Fatalf(`Invalid username, got "%v" instead of "%v"`, users[0].Username, testAdminUsername)
|
|
|
|
}
|
|
|
|
|
|
|
|
if users[0].Password != "" {
|
|
|
|
t.Fatalf(`Invalid password, got "%v"`, users[0].Password)
|
|
|
|
}
|
|
|
|
|
|
|
|
if users[0].Language != "en_US" {
|
|
|
|
t.Fatalf(`Invalid language, got "%v"`, users[0].Language)
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:51:22 -04:00
|
|
|
if users[0].Theme != "light_serif" {
|
2018-08-25 14:53:14 -04:00
|
|
|
t.Fatalf(`Invalid theme, got "%v"`, users[0].Theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if users[0].Timezone != "UTC" {
|
|
|
|
t.Fatalf(`Invalid timezone, got "%v"`, users[0].Timezone)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !users[0].IsAdmin {
|
|
|
|
t.Fatalf(`Invalid role, got "%v"`, users[0].IsAdmin)
|
|
|
|
}
|
2020-07-08 19:24:54 -04:00
|
|
|
|
|
|
|
if users[0].EntriesPerPage != 100 {
|
|
|
|
t.Fatalf(`Invalid entries per page, got "%v"`, users[0].EntriesPerPage)
|
|
|
|
}
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateStandardUser(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
t.Fatalf(`Invalid userID, got "%v"`, user.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Username != username {
|
|
|
|
t.Fatalf(`Invalid username, got "%v" instead of "%v"`, user.Username, username)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Password != "" {
|
|
|
|
t.Fatalf(`Invalid password, got "%v"`, user.Password)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Language != "en_US" {
|
|
|
|
t.Fatalf(`Invalid language, got "%v"`, user.Language)
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:51:22 -04:00
|
|
|
if user.Theme != "light_serif" {
|
2018-08-25 14:53:14 -04:00
|
|
|
t.Fatalf(`Invalid theme, got "%v"`, user.Theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Timezone != "UTC" {
|
|
|
|
t.Fatalf(`Invalid timezone, got "%v"`, user.Timezone)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.IsAdmin {
|
|
|
|
t.Fatalf(`Invalid role, got "%v"`, user.IsAdmin)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.LastLoginAt != nil {
|
|
|
|
t.Fatalf(`Invalid last login date, got "%v"`, user.LastLoginAt)
|
|
|
|
}
|
2020-07-08 19:24:54 -04:00
|
|
|
|
|
|
|
if user.EntriesPerPage != 100 {
|
|
|
|
t.Fatalf(`Invalid entries per page, got "%v"`, user.EntriesPerPage)
|
|
|
|
}
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveUser(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := client.DeleteUser(user.ID); err != nil {
|
|
|
|
t.Fatalf(`Unable to remove user: "%v"`, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUserByID(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.UserByID(99999)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Should returns a 404`)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err = client.UserByID(user.ID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
t.Fatalf(`Invalid userID, got "%v"`, user.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Username != username {
|
|
|
|
t.Fatalf(`Invalid username, got "%v" instead of "%v"`, user.Username, username)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Password != "" {
|
|
|
|
t.Fatalf(`Invalid password, got "%v"`, user.Password)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Language != "en_US" {
|
|
|
|
t.Fatalf(`Invalid language, got "%v"`, user.Language)
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:51:22 -04:00
|
|
|
if user.Theme != "light_serif" {
|
2018-08-25 14:53:14 -04:00
|
|
|
t.Fatalf(`Invalid theme, got "%v"`, user.Theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Timezone != "UTC" {
|
|
|
|
t.Fatalf(`Invalid timezone, got "%v"`, user.Timezone)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.IsAdmin {
|
|
|
|
t.Fatalf(`Invalid role, got "%v"`, user.IsAdmin)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.LastLoginAt != nil {
|
|
|
|
t.Fatalf(`Invalid last login date, got "%v"`, user.LastLoginAt)
|
|
|
|
}
|
2020-07-08 19:24:54 -04:00
|
|
|
|
|
|
|
if user.EntriesPerPage != 100 {
|
|
|
|
t.Fatalf(`Invalid entries per page, got "%v"`, user.EntriesPerPage)
|
|
|
|
}
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUserByUsername(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.UserByUsername("missinguser")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Should returns a 404`)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err = client.UserByUsername(username)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
t.Fatalf(`Invalid userID, got "%v"`, user.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Username != username {
|
|
|
|
t.Fatalf(`Invalid username, got "%v" instead of "%v"`, user.Username, username)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Password != "" {
|
|
|
|
t.Fatalf(`Invalid password, got "%v"`, user.Password)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Language != "en_US" {
|
|
|
|
t.Fatalf(`Invalid language, got "%v"`, user.Language)
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:51:22 -04:00
|
|
|
if user.Theme != "light_serif" {
|
2018-08-25 14:53:14 -04:00
|
|
|
t.Fatalf(`Invalid theme, got "%v"`, user.Theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Timezone != "UTC" {
|
|
|
|
t.Fatalf(`Invalid timezone, got "%v"`, user.Timezone)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.IsAdmin {
|
|
|
|
t.Fatalf(`Invalid role, got "%v"`, user.IsAdmin)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.LastLoginAt != nil {
|
|
|
|
t.Fatalf(`Invalid last login date, got "%v"`, user.LastLoginAt)
|
|
|
|
}
|
2020-07-08 19:24:54 -04:00
|
|
|
|
|
|
|
if user.EntriesPerPage != 100 {
|
|
|
|
t.Fatalf(`Invalid entries per page, got "%v"`, user.EntriesPerPage)
|
|
|
|
}
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateUserTheme(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:51:22 -04:00
|
|
|
theme := "dark_serif"
|
2021-01-02 19:33:41 -05:00
|
|
|
user, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{Theme: &theme})
|
2018-08-25 14:53:14 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Theme != theme {
|
|
|
|
t.Fatalf(`Unable to update user Theme: got "%v" instead of "%v"`, user.Theme, theme)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 01:05:47 -05:00
|
|
|
func TestUpdateUserFields(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
stylesheet := "body { color: red }"
|
|
|
|
swipe := false
|
|
|
|
entriesPerPage := 5
|
2021-01-02 19:33:41 -05:00
|
|
|
user, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{
|
2020-12-22 01:05:47 -05:00
|
|
|
Stylesheet: &stylesheet,
|
|
|
|
EntrySwipe: &swipe,
|
|
|
|
EntriesPerPage: &entriesPerPage,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Stylesheet != stylesheet {
|
|
|
|
t.Fatalf(`Unable to update user stylesheet: got %q instead of %q`, user.Stylesheet, stylesheet)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.EntrySwipe != swipe {
|
|
|
|
t.Fatalf(`Unable to update user EntrySwipe: got %v instead of %v`, user.EntrySwipe, swipe)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.EntriesPerPage != entriesPerPage {
|
|
|
|
t.Fatalf(`Unable to update user EntriesPerPage: got %q instead of %q`, user.EntriesPerPage, entriesPerPage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-25 14:53:14 -04:00
|
|
|
func TestUpdateUserThemeWithInvalidValue(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
theme := "something that doesn't exists"
|
2021-01-02 19:33:41 -05:00
|
|
|
_, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{Theme: &theme})
|
2018-08-25 14:53:14 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Updating a user Theme with an invalid value should raise an error`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotCreateDuplicateUser(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
_, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Duplicate users should not be allowed`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotListUsersAsNonAdmin(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
_, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client = miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
_, err = client.Users()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Standard users should not be able to list any users`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Fatal(`A "Forbidden" error should be raised`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotGetUserAsNonAdmin(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client = miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
_, err = client.UserByID(user.ID)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Standard users should not be able to get any users`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Fatal(`A "Forbidden" error should be raised`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
|
2020-12-22 18:10:42 -05:00
|
|
|
adminClient := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
|
|
|
|
usernameA := getRandomUsername()
|
|
|
|
userA, err := adminClient.CreateUser(usernameA, testStandardPassword, false)
|
2018-08-25 14:53:14 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:42 -05:00
|
|
|
usernameB := getRandomUsername()
|
|
|
|
_, err = adminClient.CreateUser(usernameB, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
entriesPerPage := 10
|
|
|
|
userAClient := miniflux.New(testBaseURL, usernameA, testStandardPassword)
|
2021-01-02 19:33:41 -05:00
|
|
|
userAAfterUpdate, err := userAClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{EntriesPerPage: &entriesPerPage})
|
2020-12-22 18:10:42 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(`Standard users should be able to update themselves`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if userAAfterUpdate.EntriesPerPage != entriesPerPage {
|
|
|
|
t.Fatalf(`The EntriesPerPage field of this user should be updated`)
|
|
|
|
}
|
|
|
|
|
|
|
|
isAdmin := true
|
2021-01-02 19:33:41 -05:00
|
|
|
_, err = userAClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{IsAdmin: &isAdmin})
|
2020-12-22 18:10:42 -05:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Standard users should not be able to become admin`)
|
|
|
|
}
|
|
|
|
|
|
|
|
userBClient := miniflux.New(testBaseURL, usernameB, testStandardPassword)
|
2021-01-02 19:33:41 -05:00
|
|
|
_, err = userBClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{})
|
2018-08-25 14:53:14 -04:00
|
|
|
if err == nil {
|
2020-12-22 18:10:42 -05:00
|
|
|
t.Fatal(`Standard users should not be able to update other users`)
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Fatal(`A "Forbidden" error should be raised`)
|
|
|
|
}
|
2020-12-22 18:10:42 -05:00
|
|
|
|
|
|
|
stylesheet := "test"
|
2021-01-02 19:33:41 -05:00
|
|
|
userC, err := adminClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{Stylesheet: &stylesheet})
|
2020-12-22 18:10:42 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(`Admin users should be able to update any users`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if userC.Stylesheet != stylesheet {
|
|
|
|
t.Fatalf(`The Stylesheet field of this user should be updated`)
|
|
|
|
}
|
2018-08-25 14:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotCreateUserAsNonAdmin(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
_, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client = miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
_, err = client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Standard users should not be able to create users`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Fatal(`A "Forbidden" error should be raised`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotDeleteUserAsNonAdmin(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client = miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
err = client.DeleteUser(user.ID)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`Standard users should not be able to remove any users`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Fatal(`A "Forbidden" error should be raised`)
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 14:46:05 -05:00
|
|
|
|
|
|
|
func TestMarkUserAsReadAsUser(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
adminClient := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user, err := adminClient.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client := miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
feed, _ := createFeed(t, client)
|
|
|
|
|
|
|
|
results, err := client.FeedEntries(feed.ID, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Failed to get entries: %v`, err)
|
|
|
|
}
|
|
|
|
if results.Total == 0 {
|
|
|
|
t.Fatalf(`Invalid number of entries: %d`, results.Total)
|
|
|
|
}
|
|
|
|
if results.Entries[0].Status != miniflux.EntryStatusUnread {
|
|
|
|
t.Fatalf(`Invalid entry status, got %q instead of %q`, results.Entries[0].Status, miniflux.EntryStatusUnread)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := client.MarkAllAsRead(user.ID); err != nil {
|
|
|
|
t.Fatalf(`Failed to mark user's unread entries as read: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
results, err = client.FeedEntries(feed.ID, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Failed to get updated entries: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range results.Entries {
|
|
|
|
if entry.Status != miniflux.EntryStatusRead {
|
|
|
|
t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCannotMarkUserAsReadAsOtherUser(t *testing.T) {
|
|
|
|
username := getRandomUsername()
|
|
|
|
adminClient := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
user1, err := adminClient.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
createFeed(t, miniflux.New(testBaseURL, username, testStandardPassword))
|
|
|
|
|
|
|
|
username2 := getRandomUsername()
|
|
|
|
if _, err = adminClient.CreateUser(username2, testStandardPassword, false); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client := miniflux.New(testBaseURL, username2, testStandardPassword)
|
|
|
|
err = client.MarkAllAsRead(user1.ID)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Non-admin users should not be able to mark another user as read`)
|
|
|
|
}
|
|
|
|
if err != miniflux.ErrForbidden {
|
|
|
|
t.Errorf(`A "Forbidden" error should be raised, got %q`, err)
|
|
|
|
}
|
|
|
|
}
|