From 9167379d53bdb8cd6d7c7e57ed62f5b711329652 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 9 Sep 2011 07:36:15 +0200 Subject: [PATCH] SONAR-2603 provide a dedicated settings page to generate server key This page is merged to the catgories of the General Settings page. At the same time the Email Settings page is merged as well. --- .../org/sonar/plugins/core/CorePlugin.java | 9 +- .../resources/org/sonar/l10n/core.properties | 10 ++- .../java/org/sonar/api/CoreProperties.java | 7 +- .../org/sonar/server/platform/Platform.java | 1 + .../org/sonar/server/platform/ServerImpl.java | 13 +-- .../server/platform/ServerKeyGenerator.java | 88 ++++++++++--------- .../java/org/sonar/server/ui/JRubyFacade.java | 10 +++ .../email_configuration_controller.rb | 1 + .../server_key_configuration_controller.rb | 55 ++++++++++++ .../app/controllers/settings_controller.rb | 5 ++ .../main/webapp/WEB-INF/app/models/server.rb | 2 +- .../views/email_configuration/index.html.erb | 61 ++++++++----- .../app/views/layouts/_layout.html.erb | 1 - .../server_key_configuration/index.html.erb | 58 ++++++++++++ .../app/views/settings/_plugins.html.erb | 20 +++-- .../app/views/settings/_special.html.erb | 1 + .../sonar/server/platform/ServerImplTest.java | 8 +- .../platform/ServerKeyGeneratorTest.java | 21 ++--- ...ml => shouldLoadServerKeyFromDatabase.xml} | 2 +- 19 files changed, 256 insertions(+), 117 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/settings/_special.html.erb rename sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/{shouldGenerateKey.xml => shouldLoadServerKeyFromDatabase.xml} (52%) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index fd6b705e6bc..354e00c9e37 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -44,18 +44,11 @@ import org.sonar.plugins.core.widgets.*; import java.util.List; @Properties({ - @Property( - key = CoreProperties.ORGANIZATION, - name = "Organization", - description = "Identify your installation. Required to generate the server key and to benefit from licensed plugins. Server must be restarted for the change to take effect.", - global = true, - category = CoreProperties.CATEGORY_GENERAL - ), @Property( key = CoreProperties.SERVER_BASE_URL, defaultValue = CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE, name = "Server base URL", - description = "HTTP address of the Sonar server, such as http://yourhost.yourdomain/sonar. This value is used i.e. to create links in emails and to generate server key.", + description = "HTTP URL of this Sonar server, such as http://yourhost.yourdomain/sonar. This value is used i.e. to create links in emails.", project = false, global = true, category = CoreProperties.CATEGORY_GENERAL), diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 43dcd6262f5..a3469eac4f0 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -425,7 +425,8 @@ dashboard.update_dashboard=Update dashboard # SETTINGS # #------------------------------------------------------------------------------ -settings.save_category=Save {0} settings +settings.save_category=Save {0} Settings +property.category.email=Email property.category.general=General property.category.security=Security property.category.java=Java @@ -433,6 +434,7 @@ property.category.differentialViews=Differential Views property.category.codeCoverage=Code Coverage property.category.duplications=Duplications property.category.localization=Localization +property.category.server_key=Server Key #------------------------------------------------------------------------------ @@ -743,7 +745,7 @@ email_configuration.from_address=From address email_configuration.from_address.description=Emails will come from this address. For example - "noreply@sonarsource.com". Note that server may ignore this setting (like does GMail). email_configuration.email_prefix=Email prefix email_configuration.email_prefix.description=This prefix will be prepended to all outgoing email subjects. -email_configuration.save_settings=Save +email_configuration.save_settings=Save Email Settings email_configuration.saving_settings=Saving email_configuration.settings_saved=Settings are saved. @@ -754,8 +756,8 @@ email_configuration.test.subject=Subject email_configuration.test.subject_text=Test Message from Sonar email_configuration.test.message=Message email_configuration.test.message_text=This is a test message from Sonar -email_configuration.test.send=Send test email -email_configuration.test.sending=Sending test email +email_configuration.test.send=Send Test Email +email_configuration.test.sending=Sending Test Email email_configuration.test.email_was_sent_to_x=Email was sent to {0} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 56e558cfd5b..df3a8584548 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -245,5 +245,10 @@ public interface CoreProperties { /** * @since 2.11 */ - String SERVER_KEY = "sonar.serverKey.secured"; + String SERVER_KEY = "sonar.server_key"; + + /** + * @since 2.11 + */ + String SERVER_KEY_IP_ADDRESS = "sonar.server_key.ip_address"; } diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index a587cce3cc3..7eb85ce851a 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -144,6 +144,7 @@ public final class Platform { coreContainer.as(Characteristics.CACHE).addComponent(UpdateCenterClient.class); coreContainer.as(Characteristics.CACHE).addComponent(UpdateCenterMatrixFactory.class); coreContainer.as(Characteristics.CACHE).addComponent(PluginDownloader.class); + coreContainer.as(Characteristics.CACHE).addComponent(ServerKeyGenerator.class); coreContainer.as(Characteristics.CACHE).addComponent(ServerImpl.class); coreContainer.as(Characteristics.NO_CACHE).addComponent(FilterExecutor.class); coreContainer.as(Characteristics.NO_CACHE).addAdapter(new DatabaseSessionProvider()); diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java index e68874e9b60..f030202c85d 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java @@ -43,16 +43,14 @@ public final class ServerImpl extends Server { * This component can't use Configuration because of startup sequence. It must be started before plugins. */ private DatabaseSessionFactory dbSessionFactory; - private ServerKeyGenerator keyGenerator; public ServerImpl(DatabaseSessionFactory dbSessionFactory) { - this(dbSessionFactory, new ServerKeyGenerator(), new Date()); + this(dbSessionFactory, new Date()); } - ServerImpl(DatabaseSessionFactory dbSessionFactory, ServerKeyGenerator keyGenerator, Date startedAt) { + ServerImpl(DatabaseSessionFactory dbSessionFactory, Date startedAt) { this.dbSessionFactory = dbSessionFactory; this.startedAt = startedAt; - this.keyGenerator = keyGenerator; } public void start() { @@ -70,11 +68,8 @@ public final class ServerImpl extends Server { public String getKey() { DatabaseSession session = dbSessionFactory.getSession(); - Property organization = session.getSingleResult(Property.class, "key", CoreProperties.ORGANIZATION); - Property baseUrl = session.getSingleResult(Property.class, "key", CoreProperties.SERVER_BASE_URL); - return keyGenerator.generate( - organization != null ? organization.getValue() : null, - baseUrl != null ? baseUrl.getValue() : null); + Property serverKey = session.getSingleResult(Property.class, "key", CoreProperties.SERVER_KEY); + return (serverKey!= null ? serverKey.getValue() : null); } public String getId() { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java index 67e73e569a7..0a29e0eb876 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java @@ -19,14 +19,18 @@ */ package org.sonar.server.platform; +import com.google.common.collect.Lists; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; -import org.sonar.api.utils.Logs; import java.io.UnsupportedEncodingException; -import java.net.*; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; import java.util.Enumeration; +import java.util.List; /** * @since 2.11 @@ -50,36 +54,17 @@ public class ServerKeyGenerator { this.acceptPrivateAddress = acceptPrivateAddress; } - public String generate(String organization, String baseUrl) { + public String generate(String organization, String ipAddress) { String key = null; - if (StringUtils.isNotBlank(organization) && StringUtils.isNotBlank(baseUrl)) { - InetAddress address = extractAddressFromUrl(baseUrl); - if (address != null && isFixed(address) && isOwner(address)) { - key = toKey(organization, address); + if (StringUtils.isNotBlank(organization) && StringUtils.isNotBlank(ipAddress)) { + InetAddress inetAddress = toValidAddress(ipAddress); + if (inetAddress != null) { + key = toKey(organization, inetAddress); } } return key; } - boolean isOwner(InetAddress address) { - try { - Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); - while (networkInterfaces.hasMoreElements()) { - NetworkInterface networkInterface = networkInterfaces.nextElement(); - Enumeration addresses = networkInterface.getInetAddresses(); - while (addresses.hasMoreElements()) { - InetAddress ownedAddress = addresses.nextElement(); - if (ownedAddress.equals(address)) { - return true; - } - } - } - } catch (SocketException e) { - LoggerFactory.getLogger(ServerKeyGenerator.class).error("Fail to verify server key. Network interfaces can't be browsed.", e); - } - return false; - } - boolean isFixed(InetAddress address) { // Loopback addresses are in the range 127/8. // Link local addresses are in the range 169.254/16 (IPv4) or fe80::/10 (IPv6). They are "autoconfiguration" addresses. @@ -87,22 +72,6 @@ public class ServerKeyGenerator { return acceptPrivateAddress || (!address.isLoopbackAddress() && !address.isLinkLocalAddress()); } - InetAddress extractAddressFromUrl(String baseUrl) { - if (StringUtils.isBlank(baseUrl)) { - return null; - } - try { - URL url = new URL(baseUrl); - return InetAddress.getByName(url.getHost()); - - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Server base URL is malformed: " + baseUrl, e); - - } catch (UnknownHostException e) { - throw new IllegalArgumentException("Server base URL is unknown: " + baseUrl, e); - } - } - String toKey(String organization, InetAddress address) { String key = new StringBuilder().append(organization).append("-").append(address.getHostAddress()).toString(); try { @@ -112,4 +81,39 @@ public class ServerKeyGenerator { throw new IllegalArgumentException("Organization is not UTF-8 encoded: " + organization, e); } } + + public InetAddress toValidAddress(String ipAddress) { + if (StringUtils.isNotBlank(ipAddress)) { + List validAddresses = getAvailableAddresses(); + try { + InetAddress address = InetAddress.getByName(ipAddress); + if (validAddresses.contains(address)) { + return address; + } + } catch (UnknownHostException e) { + // ignore, not valid property + } + } + return null; + } + + public List getAvailableAddresses() { + List result = Lists.newArrayList(); + try { + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + Enumeration addresses = networkInterface.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress ownedAddress = addresses.nextElement(); + if (isFixed(ownedAddress)) { + result.add(ownedAddress); + } + } + } + } catch (SocketException e) { + LoggerFactory.getLogger(ServerKeyGenerator.class).error("Fail to browse network interfaces", e); + } + return result; + } } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 1efadaabc4a..485a7a1b341 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -44,11 +44,13 @@ import org.sonar.server.filters.FilterExecutor; import org.sonar.server.filters.FilterResult; import org.sonar.server.notifications.reviews.ReviewsNotificationManager; import org.sonar.server.platform.Platform; +import org.sonar.server.platform.ServerKeyGenerator; import org.sonar.server.plugins.*; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.updatecenter.common.Version; +import java.net.InetAddress; import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; @@ -274,6 +276,14 @@ public final class JRubyFacade { return getContainer().getComponent(Configuration.class).getString(key, null); } + public List getValidInetAddressesForServerKey() { + return getContainer().getComponent(ServerKeyGenerator.class).getAvailableAddresses(); + } + + public String generateServerKey(String organization, String ipAddress) { + return getContainer().getComponent(ServerKeyGenerator.class).generate(organization, ipAddress); + } + public Connection getConnection() throws SQLException { return getContainer().getComponent(DatabaseConnector.class).getConnection(); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb index e8f89b50748..5e38fe875c7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb @@ -30,6 +30,7 @@ class EmailConfigurationController < ApplicationController @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT) @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT) @email_prefix = Property.value(configuration::PREFIX, nil, configuration::PREFIX_DEFAULT) + params[:layout]='false' end def save diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb new file mode 100644 index 00000000000..8e2e59fd3e1 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb @@ -0,0 +1,55 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2011 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +class ServerKeyConfigurationController < ApplicationController + + SECTION=Navigation::SECTION_CONFIGURATION + PROPERTY_SERVER_KEY = 'sonar.server_key' + PROPERTY_IP_ADDRESS = 'sonar.server_key.ip_address' + PROPERTY_ORGANIZATION = 'sonar.organization' + + before_filter :admin_required + verify :method => :post, :only => [:save], :redirect_to => {:action => :index} + + def index + @server_key = Property.value(PROPERTY_SERVER_KEY) + @organization = Property.value(PROPERTY_ORGANIZATION) + @address = Property.value(PROPERTY_IP_ADDRESS) + @valid_addresses = java_facade.getValidInetAddressesForServerKey() + params[:layout]='false' + end + + def save + organization = params[:organization] + Property.set(PROPERTY_ORGANIZATION, organization) + + ip_address=params[:address] + Property.set(PROPERTY_IP_ADDRESS, ip_address) + + key = java_facade.generate_server_key(organization, ip_address) + if key + Property.set(PROPERTY_SERVER_KEY, key) + else + Property.clear(PROPERTY_SERVER_KEY) + flash[:error] = 'Please set valid organization and IP address' + end + + redirect_to :action => 'index' + end +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb index 50085bb6289..8a052d24953 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb @@ -20,6 +20,8 @@ class SettingsController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION + + SPECIAL_CATEGORIES=['email', 'server_key'] verify :method => :post, :only => ['update'], :redirect_to => {:action => :index} @@ -80,5 +82,8 @@ class SettingsController < ApplicationController @properties_per_category[category]<<%= message('email_configuration.page') -%> -
<% form_tag({:action => 'save'}) do -%> - +
+ + + + + + - + - + - + - + - + - + + + - - + +
<%= message('email_configuration.page') -%>
<%= text_field_tag 'smtp_host', @smtp_host %> <%= message('email_configuration.smtp_host.description') -%>
<%= text_field_tag 'smtp_port', @smtp_port %> <%= message('email_configuration.smtp_port.description') -%>
<%= select_tag 'smtp_secure_connection', options_for_select({'No' => '', 'SSL' => 'ssl'}, @smtp_secure_connection) %> <%= message('email_configuration.smtp_secure_connection.description') -%>
<%= text_field_tag 'smtp_username', @smtp_username %> <%= message('email_configuration.smtp_username.description') -%>
<%= password_field_tag 'smtp_password', @smtp_password %> <%= message('email_configuration.smtp_password.description') -%>
<%= text_field_tag 'email_from', @email_from %> <%= message('email_configuration.from_address.description') -%>
<%= text_field_tag 'email_prefix', @email_prefix %> <%= message('email_configuration.email_prefix.description') -%>
<%= submit_tag message('email_configuration.save_settings'), :disable_with => message('email_configuration.saving_settings') %> + <%= submit_tag message('email_configuration.save_settings'), :disable_with => message('email_configuration.saving_settings') %> +
<% end -%> -
-

<%= message('email_configuration.test.title') -%>

-
+
+ <% form_tag({:action => 'send_test_email'}) do -%> - +
+ + + + + + + + + + + - + - + - - - - +
<%= message('email_configuration.test.title') -%>
+ <%= submit_tag message('email_configuration.test.send'), :disable_with => message('email_configuration.test.sending') %> +
<%= text_field_tag 'to_address', current_user.email %>
<%= text_field_tag 'subject', message('email_configuration.test.subject_text') %>
<%= text_area_tag 'message', message('email_configuration.test.message_text'), {:cols => 40, :rows => 6} %>
<%= submit_tag message('email_configuration.test.send'), :disable_with => message('email_configuration.test.sending') %>
<% end -%> -
+ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index 93301fc664b..634693f7384 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -90,7 +90,6 @@
  • <%= message('sidebar.system') -%>
  • <%= message('settings.page') -%>
  • -
  • <%= message('email_configuration.page') -%>
  • <%= message('backup.page') -%>
  • <%= message('system_info.page') -%>
  • <% update_center_activated = controller.java_facade.getConfigurationValue('sonar.updatecenter.activate') || 'true'; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb new file mode 100644 index 00000000000..0153c35c10b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb @@ -0,0 +1,58 @@ +

    <%= message('server_key_configuration.page') -%>

    + +<% if @server_key %> +

    Server Key: <%= @server_key -%>

    +<% else %> +<% end %> +

    + TODO.... +

    + +<% form_tag :action => :save do %> + + + + + + + + <% if @server_key %> + + + + <% end %> + + + + + + + + + + + + +
    + Changing configuration can disable your SonarSource commercial licenses. You'll have to renew them. +
    + <%= submit_tag message('server_key_configuration.save'), :disable_with => message('server_key_configuration.saving') %> +
    +

    Organization

    +

    The organization is ....

    +

    + +

    +
    +

    IP Address

    +

    The IP address is .... Choose one of the following:

    +
      + <% @valid_addresses.each_with_index do |ip_address, index| %> +
    • <%= ip_address.getHostAddress() -%>
    • + <% end %> +
    +

    + +

    +
    +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_plugins.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_plugins.html.erb index 11fffc3c8d4..ec7db02725e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_plugins.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_plugins.html.erb @@ -44,8 +44,8 @@ <% - @properties_per_category.keys.sort_by{|category| message("property.category.#{category}", :default => category)}.each do |category| - unless @properties_per_category[category].empty? + @properties_per_category.keys.sort_by{|category| message("property.category.#{category}", :default => category).upcase}.each do |category| + if !@properties_per_category[category].empty? || SettingsController::SPECIAL_CATEGORIES.include?(category) %> <%= link_to message("property.category.#{category}", :default => category), :overwrite_params => {:category => category} -%> @@ -59,10 +59,14 @@ - <% if @category && @properties_per_category[@category] && !@properties_per_category[@category].empty? - category_name = message("property.category.#{@category}", :default => @category) + <% if @category && @properties_per_category[@category] + category_name = message("property.category.#{@category}", :default => @category) + if SettingsController::SPECIAL_CATEGORIES.include?(@category) + %> + <%= render :partial => 'special', :locals => {:url => url_for(:controller => "#{@category}_configuration")} -%> + <% + elsif !@properties_per_category[@category].empty? %> - <% form_tag :controller => :settings, :action => :update do %> <%= hidden_field_tag('category', @category) -%> <% if @project %> @@ -83,7 +87,7 @@ value = Property.value(property.key(), (@project ? @project.id : nil), '') %> - +

    <%= message("property.#{property.key()}.name", :default => property.name()) -%> <% if property.project() %> @@ -120,7 +124,9 @@ <% save_message=message('settings.save_category', :params => [category_name]) %> <%= submit_tag(save_message, :disable_with => save_message, :id => 'save') -%> <% end %> - <% end %> + <% end + end + %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_special.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_special.html.erb new file mode 100644 index 00000000000..24b253c72de --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_special.html.erb @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java index 53eab63819a..835d53de9b8 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java @@ -68,12 +68,10 @@ public class ServerImplTest extends AbstractDbUnitTestCase { } @Test - public void shouldGenerateKey() { - setupData("shouldGenerateKey"); + public void shouldLoadServerKeyFromDatabase() { + setupData("shouldLoadServerKeyFromDatabase"); - ServerKeyGenerator keyGenerator = mock(ServerKeyGenerator.class); - when(keyGenerator.generate("World Company", "http://192.168.0.1")).thenReturn("abcde"); - ServerImpl server = new ServerImpl(getSessionFactory(), keyGenerator, new Date()); + ServerImpl server = new ServerImpl(getSessionFactory(), new Date()); server.start(); assertThat(server.getKey(), Is.is("abcde")); diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerKeyGeneratorTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerKeyGeneratorTest.java index 7691e7f23c0..f23abdc18c9 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/ServerKeyGeneratorTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerKeyGeneratorTest.java @@ -62,32 +62,21 @@ public class ServerKeyGeneratorTest { assertThat(new ServerKeyGenerator().isFixed(InetAddress.getByName("sonarsource.com")), Is.is(true)); } - @Test - public void shouldBeAddressOwner() throws UnknownHostException { - assertThat(new ServerKeyGenerator().isOwner(InetAddress.getByName("sonarsource.com")), Is.is(false)); - assertThat(new ServerKeyGenerator().isOwner(InetAddress.getByName("localhost")), Is.is(true)); - assertThat(new ServerKeyGenerator().isOwner(InetAddress.getByName("127.0.0.1")), Is.is(true)); - } - @Test public void keyShouldBeUniquePerOrganization() { ServerKeyGenerator generator = new ServerKeyGenerator(true); - String k1 = generator.generate("Corp One", "http://localhost:9000"); - String k2 = generator.generate("Corp Two", "http://localhost:9000"); + + String k1 = generator.generate("Corp One", "127.0.0.1"); + String k2 = generator.generate("Corp Two", "127.0.0.1"); assertThat(StringUtils.equals(k1, k2), Is.is(false)); } @Test public void keyShouldBeReproducible() { ServerKeyGenerator generator = new ServerKeyGenerator(true); - String k1 = generator.generate("SonarSource", "http://localhost:9000"); - String k2 = generator.generate("SonarSource", "http://localhost:9000"); + String k1 = generator.generate("SonarSource", "127.0.0.1"); + String k2 = generator.generate("SonarSource", "127.0.0.1"); assertThat(StringUtils.equals(k1, k2), Is.is(true)); } - @Test - public void shouldExtractAddressFromUrl() { - assertThat(new ServerKeyGenerator().extractAddressFromUrl("https://localhost:9000").getHostAddress(), Is.is("127.0.0.1")); - assertThat(new ServerKeyGenerator().extractAddressFromUrl("http://sonarsource.com/sonar").getHostName(), Is.is("sonarsource.com")); - } } diff --git a/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldGenerateKey.xml b/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldLoadServerKeyFromDatabase.xml similarity index 52% rename from sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldGenerateKey.xml rename to sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldLoadServerKeyFromDatabase.xml index df18318837d..0ca33b1e732 100644 --- a/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldGenerateKey.xml +++ b/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/shouldLoadServerKeyFromDatabase.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file -- 2.39.5