From 6745e2b4b32fd4754cbcca3c85fdaac85fcda7f7 Mon Sep 17 00:00:00 2001
From: Marcel van Remmerden <mvanremmerden@gitlab.com>
Date: Mon, 8 Jul 2024 14:45:55 +0000
Subject: [PATCH] Show confirmation that GitLab.com instance applications are
 provided by GitLab

---
 .../doorkeeper/authorizations/new.html.haml   | 11 ++++--
 locale/gitlab.pot                             |  3 ++
 .../oauth/authorizations_controller_spec.rb   | 38 +++++++++++++++++++
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/app/views/doorkeeper/authorizations/new.html.haml b/app/views/doorkeeper/authorizations/new.html.haml
index ddce6e4d4eeec..ab199e0f8b3bb 100644
--- a/app/views/doorkeeper/authorizations/new.html.haml
+++ b/app/views/doorkeeper/authorizations/new.html.haml
@@ -19,9 +19,14 @@
       .gl-text-gray-500.gl-pb-5.gl-text-sm= t scope, scope: [:doorkeeper, :scope_desc]
   .info-well
     .well-segment
-      %p.gl-text-orange-500
-        = sprite_icon('warning-solid')
-        = html_escape(_('Make sure you trust %{client_name} before authorizing.')) % { client_name: "<strong>#{html_escape(@pre_auth.client.name)}</strong>".html_safe }
+      - if Gitlab.com? && !@pre_auth.client.application.owner
+        %p.gl-text-green-500
+          = sprite_icon('tanuki-verified')
+          = _('This application is provided by GitLab.')
+      - else
+        %p.gl-text-orange-500
+          = sprite_icon('warning-solid')
+          = html_escape(_('Make sure you trust %{client_name} before authorizing.')) % { client_name: "<strong>#{html_escape(@pre_auth.client.name)}</strong>".html_safe }
       %p
         = html_escape(_('%{owner} %{created_date} ago.')) % { owner: auth_app_owner_text(@pre_auth.client.application.owner), created_date: time_ago_in_words(@pre_auth.client.application.created_at.to_date) }
         - domain = URI.parse(@pre_auth.redirect_uri).host.gsub('www.', '')
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 9d6db25474860..685cea3691e4e 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -54078,6 +54078,9 @@ msgstr ""
 msgid "This also resolves this thread"
 msgstr ""
 
+msgid "This application is provided by GitLab."
+msgstr ""
+
 msgid "This application will be able to:"
 msgstr ""
 
diff --git a/spec/controllers/oauth/authorizations_controller_spec.rb b/spec/controllers/oauth/authorizations_controller_spec.rb
index f34726fc575ff..c8c871bd616b0 100644
--- a/spec/controllers/oauth/authorizations_controller_spec.rb
+++ b/spec/controllers/oauth/authorizations_controller_spec.rb
@@ -128,6 +128,44 @@
           expect(response).to render_template('doorkeeper/authorizations/redirect')
         end
 
+        context 'when showing applications as provided' do
+          let!(:application) do
+            create(
+              :oauth_application,
+              owner_id: nil,
+              owner_type: nil,
+              scopes: application_scopes,
+              redirect_uri: 'http://example.com',
+              confidential: confidential
+            )
+          end
+
+          context 'when on GitLab.com' do
+            before do
+              allow(Gitlab).to receive(:com?).and_return(true)
+            end
+
+            it 'displays the provided application message' do
+              subject
+              expect(response.body).to have_css('p.gl-text-green-500', text: 'This application is provided by GitLab.')
+              expect(response.body).to have_css('[data-testid="tanuki-verified-icon"]')
+            end
+          end
+
+          context 'when not on GitLab.com' do
+            before do
+              allow(Gitlab).to receive(:com?).and_return(false)
+            end
+
+            it 'displays the warning message' do
+              subject
+              expect(response.body).to have_css(
+                'p.gl-text-orange-500', text: "Make sure you trust #{application.name} before authorizing.")
+              expect(response.body).to have_css('[data-testid="warning-solid-icon"]')
+            end
+          end
+        end
+
         context 'with gl_auth_type=login' do
           let(:minimal_scope) { Gitlab::Auth::READ_USER_SCOPE.to_s }
 
-- 
GitLab