From 2ab0b8552af51a9b2eed77d951ab29f56cf3d445 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Thu, 2 Feb 2023 11:01:18 +0530 Subject: [PATCH] fix: Identity JSON response header (#6326) --- app/controllers/microsoft_controller.rb | 14 +++++++++++++- app/views/microsoft/identity_association.json.erb | 7 ------- .../microsoft/identity_association.json.jbuilder | 5 +++++ spec/controllers/microsoft_controller_spec.rb | 6 +++++- 4 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 app/views/microsoft/identity_association.json.erb create mode 100644 app/views/microsoft/identity_association.json.jbuilder diff --git a/app/controllers/microsoft_controller.rb b/app/controllers/microsoft_controller.rb index 36c350c3df7c..07e58d4db85f 100644 --- a/app/controllers/microsoft_controller.rb +++ b/app/controllers/microsoft_controller.rb @@ -1,5 +1,17 @@ class MicrosoftController < ApplicationController + after_action :set_version_header + def identity_association - render layout: false + microsoft_indentity + end + + private + + def set_version_header + response.headers['Content-Length'] = { associatedApplications: [{ applicationId: @identity_json }] }.to_json.length + end + + def microsoft_indentity + @identity_json = ENV.fetch('AZURE_APP_ID', nil) end end diff --git a/app/views/microsoft/identity_association.json.erb b/app/views/microsoft/identity_association.json.erb deleted file mode 100644 index 4cfacef02c48..000000000000 --- a/app/views/microsoft/identity_association.json.erb +++ /dev/null @@ -1,7 +0,0 @@ -{ - "associatedApplications": [ - { - "applicationId": "<%= ENV['AZURE_APP_ID'] %>" - } - ] - } diff --git a/app/views/microsoft/identity_association.json.jbuilder b/app/views/microsoft/identity_association.json.jbuilder new file mode 100644 index 000000000000..ec65e01f3f86 --- /dev/null +++ b/app/views/microsoft/identity_association.json.jbuilder @@ -0,0 +1,5 @@ +json.associatedApplications do + json.array! [@identity_json] do |identity_id| + json.applicationId identity_id + end +end diff --git a/spec/controllers/microsoft_controller_spec.rb b/spec/controllers/microsoft_controller_spec.rb index 6ce22d66b487..c4b97cc13490 100644 --- a/spec/controllers/microsoft_controller_spec.rb +++ b/spec/controllers/microsoft_controller_spec.rb @@ -6,7 +6,11 @@ with_modified_env AZURE_APP_ID: 'azure-application-client-id' do get '/.well-known/microsoft-identity-association.json' expect(response).to have_http_status(:success) - expect(response.body).to include '"applicationId": "azure-application-client-id"' + expect(response.body).to include '"applicationId":"azure-application-client-id"' + + content_length = { associatedApplications: [{ applicationId: 'azure-application-client-id' }] }.to_json.length + + expect(response.headers['Content-Length']).to eq(content_length.to_s) end end end