From 958c9487fe9c6e6eae07c461e6b7da815f45550c Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 21 Feb 2022 18:45:09 +0100
Subject: [PATCH] tests gitlab

---
 ...itoryTest_test_file_creation_on_gitlab.yml |  73 ++++++++
 ...sitoryTest_test_file_destroy_on_gitlab.yml | 160 ++++++++++++++++++
 ...epositoryTest_test_file_move_on_gitlab.yml | 159 +++++++++++++++++
 ...ositoryTest_test_file_update_on_gitlab.yml | 159 +++++++++++++++++
 ...t_test_incorrect_credentials_for_gitlb.yml |  69 ++++++++
 test/services/git_repository_test.rb          |  51 ++++++
 test/support/vcr.rb                           |   2 +
 7 files changed, 673 insertions(+)
 create mode 100644 test/cassettes/GitRepositoryTest_test_file_creation_on_gitlab.yml
 create mode 100644 test/cassettes/GitRepositoryTest_test_file_destroy_on_gitlab.yml
 create mode 100644 test/cassettes/GitRepositoryTest_test_file_move_on_gitlab.yml
 create mode 100644 test/cassettes/GitRepositoryTest_test_file_update_on_gitlab.yml
 create mode 100644 test/cassettes/GitRepositoryTest_test_incorrect_credentials_for_gitlb.yml

diff --git a/test/cassettes/GitRepositoryTest_test_file_creation_on_gitlab.yml b/test/cassettes/GitRepositoryTest_test_file_creation_on_gitlab.yml
new file mode 100644
index 000000000..1463b4ab2
--- /dev/null
+++ b/test/cassettes/GitRepositoryTest_test_file_creation_on_gitlab.yml
@@ -0,0 +1,73 @@
+---
+http_interactions:
+- request:
+    method: post
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/commits
+    body:
+      encoding: UTF-8
+      string: branch=main&commit_message=Creating%20test.txt%20file&actions%5B%5D%5Baction%5D=create&actions%5B%5D%5Bfile_path%5D=test.txt&actions%5B%5D%5Bcontent%5D=content
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 201
+      message: Created
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:42:19 GMT
+      Content-Type:
+      - application/json
+      Content-Length:
+      - '694'
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"b7b38c07395e2bc0401ada2f7274d6b2"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Request-Id:
+      - 01FWEP10X1H022B1EDBF5R9BHG
+      X-Runtime:
+      - '0.573225'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-19-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-c
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=dX4etLVLLrQwKxFxhL0y45zKnFcd2Asr6YYboSUrlqd3sgyIQ8o9q20iIhKgi11UYxQpLdPnuvslaoKT8aApj3%2F8QM4xR3%2FcK%2BacWUkFQi1zBvzwyNyRdlyJTfwreZMpSCzd8ioCO0E%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c53ebd100810-CDG
+    body:
+      encoding: UTF-8
+      string: '{"id":"530b402f2c894e67af77562d98a3211511df801e","short_id":"530b402f","created_at":"2022-02-21T17:42:18.000+00:00","parent_ids":["352dbbb872f93b984c0126a1dec492f6a1ac16fa"],"title":"Creating
+        test.txt file","message":"Creating test.txt file","author_name":"Arnaud Levy","author_email":"contact@arnaudlevy.com","authored_date":"2022-02-21T17:42:18.000+00:00","committer_name":"Arnaud
+        Levy","committer_email":"contact@arnaudlevy.com","committed_date":"2022-02-21T17:42:18.000+00:00","trailers":{},"web_url":"https://gitlab.com/noesya/osuny/-/commit/530b402f2c894e67af77562d98a3211511df801e","stats":{"additions":1,"deletions":0,"total":1},"status":null,"project_id":<TEST_GITLAB_REPOSITORY>,"last_pipeline":null}'
+  recorded_at: Mon, 21 Feb 2022 17:42:19 GMT
+recorded_with: VCR 6.0.0
diff --git a/test/cassettes/GitRepositoryTest_test_file_destroy_on_gitlab.yml b/test/cassettes/GitRepositoryTest_test_file_destroy_on_gitlab.yml
new file mode 100644
index 000000000..2a9dfcd74
--- /dev/null
+++ b/test/cassettes/GitRepositoryTest_test_file_destroy_on_gitlab.yml
@@ -0,0 +1,160 @@
+---
+http_interactions:
+- request:
+    method: get
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/files/new_test.txt?ref=main
+    body:
+      encoding: US-ASCII
+      string: ''
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 200
+      message: OK
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:44:59 GMT
+      Content-Type:
+      - application/json
+      Transfer-Encoding:
+      - chunked
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"31d729b0e2a77470ec5738c0c38acd12"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Gitlab-Blob-Id:
+      - 47d2739ba2c34690248c8f91b84bb54e8936899a
+      X-Gitlab-Commit-Id:
+      - 5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a
+      X-Gitlab-Content-Sha256:
+      - fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601
+      X-Gitlab-Encoding:
+      - base64
+      X-Gitlab-File-Name:
+      - new_test.txt
+      X-Gitlab-File-Path:
+      - new_test.txt
+      X-Gitlab-Last-Commit-Id:
+      - 5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a
+      X-Gitlab-Ref:
+      - main
+      X-Gitlab-Size:
+      - '11'
+      X-Request-Id:
+      - 01FWEP5X9DXFGXP8H61A4P1CH2
+      X-Runtime:
+      - '0.081361'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-27-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-b
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=b0SCp8WwDKbKXAMqJP7BnKG9DU03F6XMtTOVsZdqPp7WSJlYhej4FTRQJ6JKHC7RVyH7siDge9CGN8%2FRiehn6ZBgO3tf9j8GW2CW1q%2FnwFOfEORxJn1ZiAmH%2BpJTFrsHc5r3c4jUoW4%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c927aae108a7-CDG
+    body:
+      encoding: ASCII-8BIT
+      string: '{"file_name":"new_test.txt","file_path":"new_test.txt","size":11,"encoding":"base64","content_sha256":"fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601","ref":"main","blob_id":"47d2739ba2c34690248c8f91b84bb54e8936899a","commit_id":"5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a","last_commit_id":"5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a","content":"bmV3IGNvbnRlbnQ="}'
+  recorded_at: Mon, 21 Feb 2022 17:44:59 GMT
+- request:
+    method: post
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/commits
+    body:
+      encoding: UTF-8
+      string: branch=main&commit_message=Destroying%20new_test.txt%20file&actions%5B%5D%5Baction%5D=delete&actions%5B%5D%5Bfile_path%5D=new_test.txt
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 201
+      message: Created
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:44:59 GMT
+      Content-Type:
+      - application/json
+      Content-Length:
+      - '706'
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"fc2b4a9db175dca1dec64814abffd823"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Request-Id:
+      - 01FWEP5XHY3KWKSDGT0YD5D8S3
+      X-Runtime:
+      - '0.407347'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-15-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-b
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=XTGmjMkPN%2FizfUO5SydebSzzrZLnjjO2rrIHROY6TYP%2Fo190%2FYpMLJhh9jh2iyRVbQa05auZ4eayQoOmCih7qJvoGDN9MCZDB%2Fm89BiYDsFhc2JmglAME8gxNcreFtawNtdYIeGRZl4%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c9296d853324-CDG
+    body:
+      encoding: UTF-8
+      string: '{"id":"0c9f41694e42f416047ff5828ad982a0fd038356","short_id":"0c9f4169","created_at":"2022-02-21T17:44:59.000+00:00","parent_ids":["5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a"],"title":"Destroying
+        new_test.txt file","message":"Destroying new_test.txt file","author_name":"Arnaud
+        Levy","author_email":"contact@arnaudlevy.com","authored_date":"2022-02-21T17:44:59.000+00:00","committer_name":"Arnaud
+        Levy","committer_email":"contact@arnaudlevy.com","committed_date":"2022-02-21T17:44:59.000+00:00","trailers":{},"web_url":"https://gitlab.com/noesya/osuny/-/commit/0c9f41694e42f416047ff5828ad982a0fd038356","stats":{"additions":0,"deletions":1,"total":1},"status":null,"project_id":<TEST_GITLAB_REPOSITORY>,"last_pipeline":null}'
+  recorded_at: Mon, 21 Feb 2022 17:44:59 GMT
+recorded_with: VCR 6.0.0
diff --git a/test/cassettes/GitRepositoryTest_test_file_move_on_gitlab.yml b/test/cassettes/GitRepositoryTest_test_file_move_on_gitlab.yml
new file mode 100644
index 000000000..c0cfae442
--- /dev/null
+++ b/test/cassettes/GitRepositoryTest_test_file_move_on_gitlab.yml
@@ -0,0 +1,159 @@
+---
+http_interactions:
+- request:
+    method: get
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/files/test.txt?ref=main
+    body:
+      encoding: US-ASCII
+      string: ''
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 200
+      message: OK
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:44:27 GMT
+      Content-Type:
+      - application/json
+      Transfer-Encoding:
+      - chunked
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"d5c7ce69cbb98d64d63988d4b7d3384f"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Gitlab-Blob-Id:
+      - 47d2739ba2c34690248c8f91b84bb54e8936899a
+      X-Gitlab-Commit-Id:
+      - 239c334f968ecbb7d350e7edfd319717891b133d
+      X-Gitlab-Content-Sha256:
+      - fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601
+      X-Gitlab-Encoding:
+      - base64
+      X-Gitlab-File-Name:
+      - test.txt
+      X-Gitlab-File-Path:
+      - test.txt
+      X-Gitlab-Last-Commit-Id:
+      - 239c334f968ecbb7d350e7edfd319717891b133d
+      X-Gitlab-Ref:
+      - main
+      X-Gitlab-Size:
+      - '11'
+      X-Request-Id:
+      - 01FWEP4YMG7J8ECYBDGBV5E0P7
+      X-Runtime:
+      - '0.076870'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-11-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-d
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=FNg9ug%2FXIRO%2B%2BpLKzAIHllWEIMmLlfU7FrfsOCcHUuGh61MJTzNXoBZ%2BcsMRWOD3uMIEeOe%2Br7tkuKtnGO5v6svpuXfLh8Cy4PzLhJoNgzf95lf6F87ng0YGtB93bKkA6RIjRK%2BtB7U%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c8638e723b49-CDG
+    body:
+      encoding: ASCII-8BIT
+      string: '{"file_name":"test.txt","file_path":"test.txt","size":11,"encoding":"base64","content_sha256":"fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601","ref":"main","blob_id":"47d2739ba2c34690248c8f91b84bb54e8936899a","commit_id":"239c334f968ecbb7d350e7edfd319717891b133d","last_commit_id":"239c334f968ecbb7d350e7edfd319717891b133d","content":"bmV3IGNvbnRlbnQ="}'
+  recorded_at: Mon, 21 Feb 2022 17:44:27 GMT
+- request:
+    method: post
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/commits
+    body:
+      encoding: UTF-8
+      string: branch=main&commit_message=Moving%20test.txt%20file&actions%5B%5D%5Baction%5D=move&actions%5B%5D%5Bfile_path%5D=new_test.txt&actions%5B%5D%5Bprevious_path%5D=test.txt&actions%5B%5D%5Baction%5D=update&actions%5B%5D%5Bfile_path%5D=new_test.txt&actions%5B%5D%5Bcontent%5D=new%20content
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 201
+      message: Created
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:44:28 GMT
+      Content-Type:
+      - application/json
+      Content-Length:
+      - '690'
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"45773ae11e4dac4015ec44d2d0d8736c"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Request-Id:
+      - 01FWEP4YX7XDERBPVFXRVE31NA
+      X-Runtime:
+      - '0.392906'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-20-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-d
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=J7nKZhEZxq7U9ETL0D52g5w%2BnbGZ4lyJvLmV%2BPvjED%2FpKh%2FgOYRlk9IHrLH4ijl2xkJc7Vwqp%2Fyu4jxU4Ay%2Bhmj91hynG1F3OTK82A6NX3l5HboRDARyGcwovF4S4XcJQsgW%2Bk0y4qI%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c8653b3a3b97-CDG
+    body:
+      encoding: UTF-8
+      string: '{"id":"5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a","short_id":"5a5bbe5f","created_at":"2022-02-21T17:44:27.000+00:00","parent_ids":["239c334f968ecbb7d350e7edfd319717891b133d"],"title":"Moving
+        test.txt file","message":"Moving test.txt file","author_name":"Arnaud Levy","author_email":"contact@arnaudlevy.com","authored_date":"2022-02-21T17:44:27.000+00:00","committer_name":"Arnaud
+        Levy","committer_email":"contact@arnaudlevy.com","committed_date":"2022-02-21T17:44:27.000+00:00","trailers":{},"web_url":"https://gitlab.com/noesya/osuny/-/commit/5a5bbe5f19533c7eaaeff596c1d866ed9f1b516a","stats":{"additions":0,"deletions":0,"total":0},"status":null,"project_id":<TEST_GITLAB_REPOSITORY>,"last_pipeline":null}'
+  recorded_at: Mon, 21 Feb 2022 17:44:28 GMT
+recorded_with: VCR 6.0.0
diff --git a/test/cassettes/GitRepositoryTest_test_file_update_on_gitlab.yml b/test/cassettes/GitRepositoryTest_test_file_update_on_gitlab.yml
new file mode 100644
index 000000000..ee74ebeb8
--- /dev/null
+++ b/test/cassettes/GitRepositoryTest_test_file_update_on_gitlab.yml
@@ -0,0 +1,159 @@
+---
+http_interactions:
+- request:
+    method: get
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/files/test.txt?ref=main
+    body:
+      encoding: US-ASCII
+      string: ''
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 200
+      message: OK
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:43:40 GMT
+      Content-Type:
+      - application/json
+      Transfer-Encoding:
+      - chunked
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"bf65869df5700fa2c2b37d91c159531f"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Gitlab-Blob-Id:
+      - 6b584e8ece562ebffc15d38808cd6b98fc3d97ea
+      X-Gitlab-Commit-Id:
+      - 530b402f2c894e67af77562d98a3211511df801e
+      X-Gitlab-Content-Sha256:
+      - ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73
+      X-Gitlab-Encoding:
+      - base64
+      X-Gitlab-File-Name:
+      - test.txt
+      X-Gitlab-File-Path:
+      - test.txt
+      X-Gitlab-Last-Commit-Id:
+      - 530b402f2c894e67af77562d98a3211511df801e
+      X-Gitlab-Ref:
+      - main
+      X-Gitlab-Size:
+      - '7'
+      X-Request-Id:
+      - 01FWEP3GGZAK3Y02B321R9JG1N
+      X-Runtime:
+      - '0.061993'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-08-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-d
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=aJ2avQf9Xt1wnNrw%2FQhH7XfbgtS%2BeC9S%2BWYzmQiv9CkgG4N26%2BFY4a86uc6yZidcv%2BrOHG7mwEWNA2eQXTX4Er6rVjnkyVBSN5FRf%2BffdUXOrO9k1oChzXMAgp4nTDkXaFqSKUyDqpA%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c73b68050814-CDG
+    body:
+      encoding: ASCII-8BIT
+      string: '{"file_name":"test.txt","file_path":"test.txt","size":7,"encoding":"base64","content_sha256":"ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73","ref":"main","blob_id":"6b584e8ece562ebffc15d38808cd6b98fc3d97ea","commit_id":"530b402f2c894e67af77562d98a3211511df801e","last_commit_id":"530b402f2c894e67af77562d98a3211511df801e","content":"Y29udGVudA=="}'
+  recorded_at: Mon, 21 Feb 2022 17:43:40 GMT
+- request:
+    method: post
+    uri: https://gitlab.com/api/v4/projects/<TEST_GITLAB_REPOSITORY>/repository/commits
+    body:
+      encoding: UTF-8
+      string: branch=main&commit_message=Updating%20test.txt%20file&actions%5B%5D%5Baction%5D=update&actions%5B%5D%5Bfile_path%5D=test.txt&actions%5B%5D%5Bcontent%5D=new%20content
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Authorization:
+      - Bearer <TEST_GITLAB_TOKEN>
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 201
+      message: Created
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:43:41 GMT
+      Content-Type:
+      - application/json
+      Content-Length:
+      - '694'
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - max-age=0, private, must-revalidate
+      Etag:
+      - W/"9941f6fc1fdc75084d905059f9890df6"
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Request-Id:
+      - 01FWEP3GRSVF4A2JAKGTS67C0Z
+      X-Runtime:
+      - '0.454585'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-26-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-d
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=aSVdIx4PQwO6I0vLGIqy0xnIY8HKdxGi%2BPzejyZTiptY4nfS9dNxfmMvU%2FERs8dEi6sG8a6XMjem0ZwLb%2BxnCTuyZQFCwvh05jo3ziBlf5w3ukTxqVspQ3y%2FWSdWM1jS5RXX3458a%2BE%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e11c73de8ec3aa5-CDG
+    body:
+      encoding: UTF-8
+      string: '{"id":"239c334f968ecbb7d350e7edfd319717891b133d","short_id":"239c334f","created_at":"2022-02-21T17:43:40.000+00:00","parent_ids":["530b402f2c894e67af77562d98a3211511df801e"],"title":"Updating
+        test.txt file","message":"Updating test.txt file","author_name":"Arnaud Levy","author_email":"contact@arnaudlevy.com","authored_date":"2022-02-21T17:43:40.000+00:00","committer_name":"Arnaud
+        Levy","committer_email":"contact@arnaudlevy.com","committed_date":"2022-02-21T17:43:40.000+00:00","trailers":{},"web_url":"https://gitlab.com/noesya/osuny/-/commit/239c334f968ecbb7d350e7edfd319717891b133d","stats":{"additions":1,"deletions":1,"total":2},"status":null,"project_id":<TEST_GITLAB_REPOSITORY>,"last_pipeline":null}'
+  recorded_at: Mon, 21 Feb 2022 17:43:41 GMT
+recorded_with: VCR 6.0.0
diff --git a/test/cassettes/GitRepositoryTest_test_incorrect_credentials_for_gitlb.yml b/test/cassettes/GitRepositoryTest_test_incorrect_credentials_for_gitlb.yml
new file mode 100644
index 000000000..f0e9e5833
--- /dev/null
+++ b/test/cassettes/GitRepositoryTest_test_incorrect_credentials_for_gitlb.yml
@@ -0,0 +1,69 @@
+---
+http_interactions:
+- request:
+    method: post
+    uri: https://gitlab.com/api/v4/projects/wrong%20id/repository/commits
+    body:
+      encoding: UTF-8
+      string: branch=main&commit_message=this%20is%20a%20commit&actions%5B%5D%5Baction%5D=create&actions%5B%5D%5Bfile_path%5D=%2Fpath.txt&actions%5B%5D%5Bcontent%5D=content
+    headers:
+      Accept:
+      - application/json
+      Content-Type:
+      - application/x-www-form-urlencoded
+      User-Agent:
+      - Gitlab Ruby Gem 4.18.0
+      Private-Token:
+      - wrong token
+      Accept-Encoding:
+      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+  response:
+    status:
+      code: 401
+      message: Unauthorized
+    headers:
+      Date:
+      - Mon, 21 Feb 2022 17:13:43 GMT
+      Content-Type:
+      - application/json
+      Content-Length:
+      - '30'
+      Connection:
+      - keep-alive
+      Cache-Control:
+      - no-cache
+      Vary:
+      - Origin
+      X-Content-Type-Options:
+      - nosniff
+      X-Frame-Options:
+      - SAMEORIGIN
+      X-Request-Id:
+      - 01FWEMCP1QMA5G62G9JVXZT97H
+      X-Runtime:
+      - '0.015819'
+      Strict-Transport-Security:
+      - max-age=31536000
+      Referrer-Policy:
+      - strict-origin-when-cross-origin
+      Gitlab-Lb:
+      - fe-18-lb-gprd
+      Gitlab-Sv:
+      - api-gke-us-east1-b
+      Cf-Cache-Status:
+      - DYNAMIC
+      Expect-Ct:
+      - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
+      Report-To:
+      - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=%2Bf2%2FgmT9DLC4VzfQjHg4AphFp9fAdQO2cyzNz8sycYn9D55r%2BZTU4ygwTDbsWYz2%2Bd6LgJ7epg8rp1ciH4DL7eZxbOBwP5bDVQcweUAAQcOo3AVbjXc4ZoHn0P3l4%2B94nWoFqMW27k0%3D"}],"group":"cf-nel","max_age":604800}'
+      Nel:
+      - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
+      Server:
+      - cloudflare
+      Cf-Ray:
+      - 6e119b5ebc493a6f-CDG
+    body:
+      encoding: UTF-8
+      string: '{"message":"401 Unauthorized"}'
+  recorded_at: Mon, 21 Feb 2022 17:13:43 GMT
+recorded_with: VCR 6.0.0
diff --git a/test/services/git_repository_test.rb b/test/services/git_repository_test.rb
index 812011646..d3044a41e 100644
--- a/test/services/git_repository_test.rb
+++ b/test/services/git_repository_test.rb
@@ -51,4 +51,55 @@ class GitRepositoryTest < ActiveSupport::TestCase
       end
     end
   end
+
+  test "incorrect credentials for gitlb" do
+    VCR.use_cassette(location) do
+      exception = assert_raises(Exception) do
+        provider = Git::Providers::Gitlab.new 'wrong token', 'wrong id'
+        provider.create_file '/path.txt', 'content'
+        provider.push 'this is a commit'
+      end
+      assert_equal exception.class, Gitlab::Error::Unauthorized
+    end
+  end
+
+  test "file creation on gitlab" do
+    VCR.use_cassette(location) do
+      assert_nothing_raised do
+        provider = Git::Providers::Gitlab.new ENV['TEST_GITLAB_TOKEN'], ENV['TEST_GITLAB_REPOSITORY']
+        provider.create_file 'test.txt', 'content'
+        result = provider.push 'Creating test.txt file'
+      end
+    end
+  end
+
+  test "file update on gitlab" do
+    VCR.use_cassette(location) do
+      assert_nothing_raised do
+        provider = Git::Providers::Gitlab.new ENV['TEST_GITLAB_TOKEN'], ENV['TEST_GITLAB_REPOSITORY']
+        provider.update_file 'test.txt', 'test.txt', 'new content'
+        result = provider.push 'Updating test.txt file'
+      end
+    end
+  end
+
+  test "file move on gitlab" do
+    VCR.use_cassette(location) do
+      assert_nothing_raised do
+        provider = Git::Providers::Gitlab.new ENV['TEST_GITLAB_TOKEN'], ENV['TEST_GITLAB_REPOSITORY']
+        provider.update_file 'new_test.txt', 'test.txt', 'new content'
+        result = provider.push 'Moving test.txt file'
+      end
+    end
+  end
+
+  test "file destroy on gitlab" do
+    VCR.use_cassette(location) do
+      assert_nothing_raised do
+        provider = Git::Providers::Gitlab.new ENV['TEST_GITLAB_TOKEN'], ENV['TEST_GITLAB_REPOSITORY']
+        provider.destroy_file 'new_test.txt'
+        result = provider.push 'Destroying new_test.txt file'
+      end
+    end
+  end
 end
diff --git a/test/support/vcr.rb b/test/support/vcr.rb
index 9dffdef91..d9d4c97be 100644
--- a/test/support/vcr.rb
+++ b/test/support/vcr.rb
@@ -6,4 +6,6 @@ VCR.configure do |c|
   c.allow_http_connections_when_no_cassette = false
   c.filter_sensitive_data('<TEST_GITHUB_TOKEN>') { ENV['TEST_GITHUB_TOKEN'] }
   c.filter_sensitive_data('<TEST_GITHUB_REPOSITORY>') { ENV['TEST_GITHUB_REPOSITORY'] }
+  c.filter_sensitive_data('<TEST_GITLAB_TOKEN>') { ENV['TEST_GITLAB_TOKEN'] }
+  c.filter_sensitive_data('<TEST_GITLAB_REPOSITORY>') { ENV['TEST_GITLAB_REPOSITORY'] }
 end
-- 
GitLab