diff options
Diffstat (limited to 'sonar-server')
16 files changed, 243 insertions, 104 deletions
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<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); - while (networkInterfaces.hasMoreElements()) { - NetworkInterface networkInterface = networkInterfaces.nextElement(); - Enumeration<InetAddress> 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<InetAddress> 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<InetAddress> getAvailableAddresses() { + List<InetAddress> result = Lists.newArrayList(); + try { + Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + Enumeration<InetAddress> 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<InetAddress> 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]<<property end end + SPECIAL_CATEGORIES.each do |category| + @properties_per_category[category]=[] + end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb index 08bc8b4b847..0fa8dd7237b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb @@ -59,7 +59,7 @@ class Server def sonar_info sonar_info=[] - add_property(sonar_info, 'Server Key') {org.sonar.server.platform.Platform.getServer().getKey()} + add_property(sonar_info, 'Server Key') {sonar_property('sonar.server_key')} add_property(sonar_info, 'Version') {org.sonar.server.platform.Platform.getServer().getVersion()} add_property(sonar_info, 'Started at') {org.sonar.server.platform.Platform.getServer().getStartedAt()} add_property(sonar_info, 'Database') {"#{jdbc_metadata. getDatabaseProductName()} #{jdbc_metadata. getDatabaseProductVersion()}"} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb index 04e91ee296c..1910f706aa7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb @@ -1,70 +1,87 @@ -<h1><%= message('email_configuration.page') -%></h1> -<div class="admin"> <% form_tag({:action => 'save'}) do -%> - <table class="form"> + <table class="data form marginbottom10"> + <thead> <tr> + <th><span><%= message('email_configuration.page') -%></span></th> + </tr> + </thead> + <tbody> + <tr class="even"> <td class="keyCell"><label for="smtp_host"><%= message('email_configuration.smtp_host') -%>:</label></td> <td><%= text_field_tag 'smtp_host', @smtp_host %></td> <td class="comments"><%= message('email_configuration.smtp_host.description') -%></td> </tr> - <tr> + <tr class="odd"> <td class="keyCell"><label for="smtp_port"><%= message('email_configuration.smtp_port') -%>:</label></td> <td><%= text_field_tag 'smtp_port', @smtp_port %></td> <td class="comments"><%= message('email_configuration.smtp_port.description') -%></td> </tr> - <tr> + <tr class="even"> <td class="keyCell"><label for="smtp_secure_connection"><%= message('email_configuration.smtp_secure_connection') -%>:</label></td> <td><%= select_tag 'smtp_secure_connection', options_for_select({'No' => '', 'SSL' => 'ssl'}, @smtp_secure_connection) %></td> <td class="comments"><%= message('email_configuration.smtp_secure_connection.description') -%></td> </tr> - <tr> + <tr class="odd"> <td class="keyCell"><label for="smtp_username"><%= message('email_configuration.smtp_username') -%>:</label></td> <td><%= text_field_tag 'smtp_username', @smtp_username %></td> <td class="comments"><%= message('email_configuration.smtp_username.description') -%></td> </tr> - <tr> + <tr class="even"> <td class="keyCell"><label for="smtp_password"><%= message('email_configuration.smtp_password') -%>:</label></td> <td><%= password_field_tag 'smtp_password', @smtp_password %></td> <td class="comments"><%= message('email_configuration.smtp_password.description') -%></td> </tr> - <tr> + <tr class="odd"> <td class="keyCell"><label for="email_from"><%= message('email_configuration.from_address') -%>:</label></td> <td><%= text_field_tag 'email_from', @email_from %></td> <td class="comments"><%= message('email_configuration.from_address.description') -%></td> </tr> - <tr> + <tr class="even"> <td class="keyCell"><label for="email_prefix"><%= message('email_configuration.email_prefix') -%>:</label></td> <td><%= text_field_tag 'email_prefix', @email_prefix %></td> <td class="comments"><%= message('email_configuration.email_prefix.description') -%></td> </tr> + </tbody> + <tfoot> <tr> - <td></td> - <td><%= submit_tag message('email_configuration.save_settings'), :disable_with => message('email_configuration.saving_settings') %></td> + <td colspan="3"> + <%= submit_tag message('email_configuration.save_settings'), :disable_with => message('email_configuration.saving_settings') %> + </td> </tr> + </tfoot> </table> <% end -%> -</div> -<h1><%= message('email_configuration.test.title') -%></h1> -<div class="admin"> +<br/> + <% form_tag({:action => 'send_test_email'}) do -%> - <table class="form"> + <table class="data form marginbottom10"> + <thead> <tr> + <th><span><%= message('email_configuration.test.title') -%></span></th> + </tr> + </thead> + <tfoot> + <tr> + <td colspan="3"> + <%= submit_tag message('email_configuration.test.send'), :disable_with => message('email_configuration.test.sending') %> + </td> + </tr> + </tfoot> + <tbody> + <tr class="even"> <td class="keyCell"><label for="to_address"><%= message('email_configuration.test.to_address') -%>:</label></td> <td><%= text_field_tag 'to_address', current_user.email %></td> </tr> - <tr> + <tr class="odd"> <td class="keyCell"><label for="subject"><%= message('email_configuration.test.subject') -%>:</label></td> <td><%= text_field_tag 'subject', message('email_configuration.test.subject_text') %></td> </tr> - <tr> + <tr class="even"> <td class="keyCell"><label for="message"><%= message('email_configuration.test.message') -%>:</label></td> <td><%= text_area_tag 'message', message('email_configuration.test.message_text'), {:cols => 40, :rows => 6} %></td> </tr> - <tr> - <td></td> - <td><%= submit_tag message('email_configuration.test.send'), :disable_with => message('email_configuration.test.sending') %></td> - </tr> + </tbody> </table> <% end -%> -</div> + 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 @@ <li class="h2"><%= message('sidebar.system') -%></li> <li class="<%= 'selected' if request.request_uri.include?('/settings') -%>"><a href="<%= ApplicationController.root_context -%>/settings/index"><%= message('settings.page') -%></a></li> - <li class="<%= 'selected' if controller.controller_path=='email_configuration' -%>"><a href="<%= ApplicationController.root_context -%>/email_configuration"><%= message('email_configuration.page') -%></a></li> <li class="<%= 'selected' if controller.controller_path=='backup' -%>"><a href="<%= ApplicationController.root_context -%>/backup"><%= message('backup.page') -%></a></li> <li class="<%= 'selected' if controller.controller_path=='system' -%>"><a href="<%= ApplicationController.root_context -%>/system"><%= message('system_info.page') -%></a></li> <% 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 @@ +<h3 class="marginbottom10"><%= message('server_key_configuration.page') -%></h3> + +<% if @server_key %> + <p>Server Key: <span class="notice"><b><%= @server_key -%></b></span></p> +<% else %> +<% end %> +<p> + TODO.... +</p> + +<% form_tag :action => :save do %> + <table class="data marginbottom10"> + <thead> + <tr> + <th></th> + </tr> + </thead> + <tfoot> + <% if @server_key %> + <tr> + <td colspan="3"> + <span class="warning">Changing configuration can disable your SonarSource commercial licenses. You'll have to renew them.</span> + </td> + </tr> + <% end %> + <tr> + <td colspan="3"> + <%= submit_tag message('server_key_configuration.save'), :disable_with => message('server_key_configuration.saving') %> + </td> + </tr> + </tfoot> + <tbody> + <tr class="even"> + <td style="padding: 10px"> + <h3>Organization</h3> + <p class="marginbottom10">The organization is ....</p> + <p> + <input type="text" name="organization" value="<%= @organization -%>"/> + </p> + </td> + </tr> + <tr class="odd"> + <td style="padding: 10px"> + <h3>IP Address</h3> + <p class="marginbottom10">The IP address is .... Choose one of the following:</p> + <ul class="marginbottom10 bullet"> + <% @valid_addresses.each_with_index do |ip_address, index| %> + <li><span class="address_<%= index -%>"><%= ip_address.getHostAddress() -%></span></li> + <% end %> + </ul> + <p> + <input type="text" name="address" value="<%= @address -%>"/> + </p> + </td> + </tr> + </tbody> + </table> +<% 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 @@ </thead> <tbody> <% - @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) %> <tr class="select <%= cycle('even', 'odd', :name => 'category') -%> <%= 'selected' if @category==category -%>" id="select_<%= category -%>"> <td><%= link_to message("property.category.#{category}", :default => category), :overwrite_params => {:category => category} -%></td> @@ -59,10 +59,14 @@ </td> <td class="column"> - <% 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), '') %> <tr class="<%= cycle('even', 'odd', :name => 'properties') -%>"> - <td style="padding: 10px"> + <td style="padding: 10px"> <h3> <%= 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 + %> </td> </tr> </table> 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 @@ +<iframe src="<%= url -%>" width="100%" height="600" frameborder="0" scrolling="no"></iframe>
\ 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 @@ -63,31 +63,20 @@ public class ServerKeyGeneratorTest { } @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 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 @@ <dataset> - <properties id="1" prop_key="sonar.organization" text_value="World Company" resource_id="[null]" user_id="[null]"/> + <properties id="1" prop_key="sonar.server_key" text_value="abcde" resource_id="[null]" user_id="[null]"/> <properties id="2" prop_key="sonar.core.serverBaseURL" text_value="http://192.168.0.1" resource_id="[null]" user_id="[null]"/> </dataset>
\ No newline at end of file |