2022-10-17 18:23:27 +02:00
// Copyright 2022 The Gitea Authors. All rights reserved.
2022-11-27 19:20:29 +01:00
// SPDX-License-Identifier: MIT
2022-10-17 18:23:27 +02:00
package integration
import (
"net/http"
"testing"
2023-10-20 11:40:32 +02:00
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
2022-10-17 18:23:27 +02:00
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
2024-07-30 21:41:10 +02:00
"github.com/stretchr/testify/require"
2022-10-17 18:23:27 +02:00
)
func TestFeed ( t * testing . T ) {
2024-10-22 15:15:09 +02:00
defer tests . AddFixtures ( "tests/integration/fixtures/TestFeed/" ) ( )
2023-10-20 11:40:32 +02:00
defer tests . PrepareTestEnv ( t ) ( )
2022-10-17 18:23:27 +02:00
t . Run ( "User" , func ( t * testing . T ) {
t . Run ( "Atom" , func ( t * testing . T ) {
2023-10-20 11:40:32 +02:00
defer tests . PrintCurrentTest ( t ) ( )
2022-10-17 18:23:27 +02:00
req := NewRequest ( t , "GET" , "/user2.atom" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <feed xmlns="http://www.w3.org/2005/Atom" ` )
} )
t . Run ( "RSS" , func ( t * testing . T ) {
2023-10-20 11:40:32 +02:00
defer tests . PrintCurrentTest ( t ) ( )
2022-10-17 18:23:27 +02:00
req := NewRequest ( t , "GET" , "/user2.rss" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <rss version="2.0" ` )
} )
} )
2023-10-20 11:40:32 +02:00
t . Run ( "Repo" , func ( t * testing . T ) {
t . Run ( "Normal" , func ( t * testing . T ) {
2024-10-22 15:15:09 +02:00
t . Run ( "Atom" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user2/repo1.atom" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <feed xmlns="http://www.w3.org/2005/Atom" ` )
assert . Contains ( t , data , "This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
} )
t . Run ( "RSS" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user2/repo1.rss" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <rss version="2.0" ` )
assert . Contains ( t , data , "This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
} )
} )
t . Run ( "Branch" , func ( t * testing . T ) {
2023-10-20 11:40:32 +02:00
t . Run ( "Atom" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user2/repo1/atom/branch/master" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <feed xmlns="http://www.w3.org/2005/Atom" ` )
} )
t . Run ( "RSS" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user2/repo1/rss/branch/master" )
resp := MakeRequest ( t , req , http . StatusOK )
data := resp . Body . String ( )
assert . Contains ( t , data , ` <rss version="2.0" ` )
} )
} )
t . Run ( "Empty" , func ( t * testing . T ) {
err := user_model . UpdateUserCols ( db . DefaultContext , & user_model . User { ID : 30 , ProhibitLogin : false } , "prohibit_login" )
2024-07-30 21:41:10 +02:00
require . NoError ( t , err )
2023-10-20 11:40:32 +02:00
session := loginUser ( t , "user30" )
t . Run ( "Atom" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user30/empty/atom/branch/master" )
session . MakeRequest ( t , req , http . StatusNotFound )
req = NewRequest ( t , "GET" , "/user30/empty.atom/src/branch/master" )
session . MakeRequest ( t , req , http . StatusNotFound )
} )
t . Run ( "RSS" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/user30/empty/rss/branch/master" )
session . MakeRequest ( t , req , http . StatusNotFound )
req = NewRequest ( t , "GET" , "/user30/empty.rss/src/branch/master" )
session . MakeRequest ( t , req , http . StatusNotFound )
} )
} )
} )
2024-11-02 17:41:34 +01:00
t . Run ( "View permission" , func ( t * testing . T ) {
t . Run ( "Anomynous" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , "/org3/repo3/rss/branch/master" )
MakeRequest ( t , req , http . StatusNotFound )
} )
t . Run ( "No code permission" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
session := loginUser ( t , "user8" )
req := NewRequest ( t , "GET" , "/org3/repo3/rss/branch/master" )
session . MakeRequest ( t , req , http . StatusNotFound )
} )
t . Run ( "With code permission" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
session := loginUser ( t , "user9" )
req := NewRequest ( t , "GET" , "/org3/repo3/rss/branch/master" )
session . MakeRequest ( t , req , http . StatusOK )
} )
} )
2022-10-17 18:23:27 +02:00
}