Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

239 lines
8.2 KiB

  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
  5. import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
  6. const expect = chai.expect
  7. describe('Test follow constraints', function () {
  8. let servers: PeerTubeServer[] = []
  9. let video1UUID: string
  10. let video2UUID: string
  11. let userToken: string
  12. before(async function () {
  13. this.timeout(240000)
  14. servers = await createMultipleServers(2)
  15. // Get the access tokens
  16. await setAccessTokensToServers(servers)
  17. {
  18. const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
  19. video1UUID = uuid
  20. }
  21. {
  22. const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
  23. video2UUID = uuid
  24. }
  25. const user = {
  26. username: 'user1',
  27. password: 'super_password'
  28. }
  29. await servers[0].users.create({ username: user.username, password: user.password })
  30. userToken = await servers[0].login.getAccessToken(user)
  31. await doubleFollow(servers[0], servers[1])
  32. })
  33. describe('With a followed instance', function () {
  34. describe('With an unlogged user', function () {
  35. it('Should get the local video', async function () {
  36. await servers[0].videos.get({ id: video1UUID })
  37. })
  38. it('Should get the remote video', async function () {
  39. await servers[0].videos.get({ id: video2UUID })
  40. })
  41. it('Should list local account videos', async function () {
  42. const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port })
  43. expect(total).to.equal(1)
  44. expect(data).to.have.lengthOf(1)
  45. })
  46. it('Should list remote account videos', async function () {
  47. const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port })
  48. expect(total).to.equal(1)
  49. expect(data).to.have.lengthOf(1)
  50. })
  51. it('Should list local channel videos', async function () {
  52. const handle = 'root_channel@localhost:' + servers[0].port
  53. const { total, data } = await servers[0].videos.listByChannel({ handle })
  54. expect(total).to.equal(1)
  55. expect(data).to.have.lengthOf(1)
  56. })
  57. it('Should list remote channel videos', async function () {
  58. const handle = 'root_channel@localhost:' + servers[1].port
  59. const { total, data } = await servers[0].videos.listByChannel({ handle })
  60. expect(total).to.equal(1)
  61. expect(data).to.have.lengthOf(1)
  62. })
  63. })
  64. describe('With a logged user', function () {
  65. it('Should get the local video', async function () {
  66. await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
  67. })
  68. it('Should get the remote video', async function () {
  69. await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
  70. })
  71. it('Should list local account videos', async function () {
  72. const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
  73. expect(total).to.equal(1)
  74. expect(data).to.have.lengthOf(1)
  75. })
  76. it('Should list remote account videos', async function () {
  77. const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
  78. expect(total).to.equal(1)
  79. expect(data).to.have.lengthOf(1)
  80. })
  81. it('Should list local channel videos', async function () {
  82. const handle = 'root_channel@localhost:' + servers[0].port
  83. const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
  84. expect(total).to.equal(1)
  85. expect(data).to.have.lengthOf(1)
  86. })
  87. it('Should list remote channel videos', async function () {
  88. const handle = 'root_channel@localhost:' + servers[1].port
  89. const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
  90. expect(total).to.equal(1)
  91. expect(data).to.have.lengthOf(1)
  92. })
  93. })
  94. })
  95. describe('With a non followed instance', function () {
  96. before(async function () {
  97. this.timeout(30000)
  98. await servers[0].follows.unfollow({ target: servers[1] })
  99. })
  100. describe('With an unlogged user', function () {
  101. it('Should get the local video', async function () {
  102. await servers[0].videos.get({ id: video1UUID })
  103. })
  104. it('Should not get the remote video', async function () {
  105. const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
  106. const error = body as unknown as PeerTubeProblemDocument
  107. const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
  108. expect(error.type).to.equal(doc)
  109. expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
  110. expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
  111. expect(error.error).to.equal(error.detail)
  112. expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
  113. expect(error.originUrl).to.contains(servers[1].url)
  114. })
  115. it('Should list local account videos', async function () {
  116. const { total, data } = await servers[0].videos.listByAccount({
  117. token: null,
  118. handle: 'root@localhost:' + servers[0].port
  119. })
  120. expect(total).to.equal(1)
  121. expect(data).to.have.lengthOf(1)
  122. })
  123. it('Should not list remote account videos', async function () {
  124. const { total, data } = await servers[0].videos.listByAccount({
  125. token: null,
  126. handle: 'root@localhost:' + servers[1].port
  127. })
  128. expect(total).to.equal(0)
  129. expect(data).to.have.lengthOf(0)
  130. })
  131. it('Should list local channel videos', async function () {
  132. const handle = 'root_channel@localhost:' + servers[0].port
  133. const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
  134. expect(total).to.equal(1)
  135. expect(data).to.have.lengthOf(1)
  136. })
  137. it('Should not list remote channel videos', async function () {
  138. const handle = 'root_channel@localhost:' + servers[1].port
  139. const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
  140. expect(total).to.equal(0)
  141. expect(data).to.have.lengthOf(0)
  142. })
  143. })
  144. describe('With a logged user', function () {
  145. it('Should get the local video', async function () {
  146. await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
  147. })
  148. it('Should get the remote video', async function () {
  149. await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
  150. })
  151. it('Should list local account videos', async function () {
  152. const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
  153. expect(total).to.equal(1)
  154. expect(data).to.have.lengthOf(1)
  155. })
  156. it('Should list remote account videos', async function () {
  157. const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
  158. expect(total).to.equal(1)
  159. expect(data).to.have.lengthOf(1)
  160. })
  161. it('Should list local channel videos', async function () {
  162. const handle = 'root_channel@localhost:' + servers[0].port
  163. const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
  164. expect(total).to.equal(1)
  165. expect(data).to.have.lengthOf(1)
  166. })
  167. it('Should list remote channel videos', async function () {
  168. const handle = 'root_channel@localhost:' + servers[1].port
  169. const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
  170. expect(total).to.equal(1)
  171. expect(data).to.have.lengthOf(1)
  172. })
  173. })
  174. })
  175. after(async function () {
  176. await cleanupTests(servers)
  177. })
  178. })