Revision 1298:4f746d8966dd .svn/pristine/25
| .svn/pristine/25/25113ec5e4b14337a78af5200fc4c9451ad1548e.svn-base | ||
|---|---|---|
| 1 |
<% @entries.each do |entry| %> |
|
| 2 |
<% tr_id = Digest::MD5.hexdigest(entry.path) |
|
| 3 |
depth = params[:depth].to_i %> |
|
| 4 |
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(entry.path) %> |
|
| 5 |
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %> |
|
| 6 |
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>"> |
|
| 7 |
<td style="padding-left: <%=18 * depth%>px;" class="<%= |
|
| 8 |
@repository.report_last_commit ? "filename" : "filename_no_report" %>";> |
|
| 9 |
<% if entry.is_dir? %> |
|
| 10 |
<span class="expander" onclick="<%= remote_function( |
|
| 11 |
:url => {
|
|
| 12 |
:action => 'show', |
|
| 13 |
:id => @project, |
|
| 14 |
:path => to_path_param(ent_path), |
|
| 15 |
:rev => @rev, |
|
| 16 |
:depth => (depth + 1), |
|
| 17 |
:parent_id => tr_id |
|
| 18 |
}, |
|
| 19 |
:method => :get, |
|
| 20 |
:update => { :success => tr_id },
|
|
| 21 |
:position => :after, |
|
| 22 |
:success => "scmEntryLoaded('#{tr_id}')",
|
|
| 23 |
:condition => "scmEntryClick('#{tr_id}')"
|
|
| 24 |
) %>"> </span> |
|
| 25 |
<% end %> |
|
| 26 |
<%= link_to h(ent_name), |
|
| 27 |
{:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(ent_path), :rev => @rev},
|
|
| 28 |
:class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(ent_name)}")%>
|
|
| 29 |
</td> |
|
| 30 |
<td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td> |
|
| 31 |
<% changeset = @project.repository.find_changeset_by_name(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> |
|
| 32 |
<% if @repository.report_last_commit %> |
|
| 33 |
<td class="revision"><%= link_to_revision(changeset, @project) if changeset %></td> |
|
| 34 |
<td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td> |
|
| 35 |
<td class="author"><%= changeset.nil? ? h(Redmine::CodesetUtil.replace_invalid_utf8(entry.lastrev.author.to_s.split('<').first)) : h(changeset.author) if entry.lastrev %></td>
|
|
| 36 |
<td class="comments"><%=h truncate(changeset.comments, :length => 50) unless changeset.nil? %></td> |
|
| 37 |
<% end %> |
|
| 38 |
</tr> |
|
| 39 |
<% end %> |
|
| .svn/pristine/25/252339adc97bdbe7fac1c5b16dba024f1d817a65.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class QueriesControllerTest < ActionController::TestCase |
|
| 21 |
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules |
|
| 22 |
|
|
| 23 |
def setup |
|
| 24 |
User.current = nil |
|
| 25 |
end |
|
| 26 |
|
|
| 27 |
def test_index |
|
| 28 |
get :index |
|
| 29 |
# HTML response not implemented |
|
| 30 |
assert_response 406 |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def test_new_project_query |
|
| 34 |
@request.session[:user_id] = 2 |
|
| 35 |
get :new, :project_id => 1 |
|
| 36 |
assert_response :success |
|
| 37 |
assert_template 'new' |
|
| 38 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 39 |
:name => 'query[is_public]', |
|
| 40 |
:checked => nil } |
|
| 41 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 42 |
:name => 'query_is_for_all', |
|
| 43 |
:checked => nil, |
|
| 44 |
:disabled => nil } |
|
| 45 |
assert_select 'select[name=?]', 'c[]' do |
|
| 46 |
assert_select 'option[value=tracker]' |
|
| 47 |
assert_select 'option[value=subject]' |
|
| 48 |
end |
|
| 49 |
end |
|
| 50 |
|
|
| 51 |
def test_new_global_query |
|
| 52 |
@request.session[:user_id] = 2 |
|
| 53 |
get :new |
|
| 54 |
assert_response :success |
|
| 55 |
assert_template 'new' |
|
| 56 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 57 |
:name => 'query[is_public]' } |
|
| 58 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 59 |
:name => 'query_is_for_all', |
|
| 60 |
:checked => 'checked', |
|
| 61 |
:disabled => nil } |
|
| 62 |
end |
|
| 63 |
|
|
| 64 |
def test_new_on_invalid_project |
|
| 65 |
@request.session[:user_id] = 2 |
|
| 66 |
get :new, :project_id => 'invalid' |
|
| 67 |
assert_response 404 |
|
| 68 |
end |
|
| 69 |
|
|
| 70 |
def test_create_project_public_query |
|
| 71 |
@request.session[:user_id] = 2 |
|
| 72 |
post :create, |
|
| 73 |
:project_id => 'ecookbook', |
|
| 74 |
:default_columns => '1', |
|
| 75 |
:f => ["status_id", "assigned_to_id"], |
|
| 76 |
:op => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
| 77 |
:v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
|
| 78 |
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
|
|
| 79 |
|
|
| 80 |
q = Query.find_by_name('test_new_project_public_query')
|
|
| 81 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
| 82 |
assert q.is_public? |
|
| 83 |
assert q.has_default_columns? |
|
| 84 |
assert q.valid? |
|
| 85 |
end |
|
| 86 |
|
|
| 87 |
def test_create_project_private_query |
|
| 88 |
@request.session[:user_id] = 3 |
|
| 89 |
post :create, |
|
| 90 |
:project_id => 'ecookbook', |
|
| 91 |
:default_columns => '1', |
|
| 92 |
:fields => ["status_id", "assigned_to_id"], |
|
| 93 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
| 94 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
|
| 95 |
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
|
|
| 96 |
|
|
| 97 |
q = Query.find_by_name('test_new_project_private_query')
|
|
| 98 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
| 99 |
assert !q.is_public? |
|
| 100 |
assert q.has_default_columns? |
|
| 101 |
assert q.valid? |
|
| 102 |
end |
|
| 103 |
|
|
| 104 |
def test_create_global_private_query_with_custom_columns |
|
| 105 |
@request.session[:user_id] = 3 |
|
| 106 |
post :create, |
|
| 107 |
:fields => ["status_id", "assigned_to_id"], |
|
| 108 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
| 109 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
|
| 110 |
:query => {"name" => "test_new_global_private_query", "is_public" => "1"},
|
|
| 111 |
:c => ["", "tracker", "subject", "priority", "category"] |
|
| 112 |
|
|
| 113 |
q = Query.find_by_name('test_new_global_private_query')
|
|
| 114 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
| 115 |
assert !q.is_public? |
|
| 116 |
assert !q.has_default_columns? |
|
| 117 |
assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
|
| 118 |
assert q.valid? |
|
| 119 |
end |
|
| 120 |
|
|
| 121 |
def test_create_global_query_with_custom_filters |
|
| 122 |
@request.session[:user_id] = 3 |
|
| 123 |
post :create, |
|
| 124 |
:fields => ["assigned_to_id"], |
|
| 125 |
:operators => {"assigned_to_id" => "="},
|
|
| 126 |
:values => { "assigned_to_id" => ["me"]},
|
|
| 127 |
:query => {"name" => "test_new_global_query"}
|
|
| 128 |
|
|
| 129 |
q = Query.find_by_name('test_new_global_query')
|
|
| 130 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
| 131 |
assert !q.has_filter?(:status_id) |
|
| 132 |
assert_equal ['assigned_to_id'], q.filters.keys |
|
| 133 |
assert q.valid? |
|
| 134 |
end |
|
| 135 |
|
|
| 136 |
def test_create_with_sort |
|
| 137 |
@request.session[:user_id] = 1 |
|
| 138 |
post :create, |
|
| 139 |
:default_columns => '1', |
|
| 140 |
:operators => {"status_id" => "o"},
|
|
| 141 |
:values => {"status_id" => ["1"]},
|
|
| 142 |
:query => {:name => "test_new_with_sort",
|
|
| 143 |
:is_public => "1", |
|
| 144 |
:sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
|
|
| 145 |
|
|
| 146 |
query = Query.find_by_name("test_new_with_sort")
|
|
| 147 |
assert_not_nil query |
|
| 148 |
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
| 149 |
end |
|
| 150 |
|
|
| 151 |
def test_create_with_failure |
|
| 152 |
@request.session[:user_id] = 2 |
|
| 153 |
assert_no_difference '::Query.count' do |
|
| 154 |
post :create, :project_id => 'ecookbook', :query => {:name => ''}
|
|
| 155 |
end |
|
| 156 |
assert_response :success |
|
| 157 |
assert_template 'new' |
|
| 158 |
assert_select 'input[name=?]', 'query[name]' |
|
| 159 |
end |
|
| 160 |
|
|
| 161 |
def test_edit_global_public_query |
|
| 162 |
@request.session[:user_id] = 1 |
|
| 163 |
get :edit, :id => 4 |
|
| 164 |
assert_response :success |
|
| 165 |
assert_template 'edit' |
|
| 166 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 167 |
:name => 'query[is_public]', |
|
| 168 |
:checked => 'checked' } |
|
| 169 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 170 |
:name => 'query_is_for_all', |
|
| 171 |
:checked => 'checked', |
|
| 172 |
:disabled => 'disabled' } |
|
| 173 |
end |
|
| 174 |
|
|
| 175 |
def test_edit_global_private_query |
|
| 176 |
@request.session[:user_id] = 3 |
|
| 177 |
get :edit, :id => 3 |
|
| 178 |
assert_response :success |
|
| 179 |
assert_template 'edit' |
|
| 180 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 181 |
:name => 'query[is_public]' } |
|
| 182 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 183 |
:name => 'query_is_for_all', |
|
| 184 |
:checked => 'checked', |
|
| 185 |
:disabled => 'disabled' } |
|
| 186 |
end |
|
| 187 |
|
|
| 188 |
def test_edit_project_private_query |
|
| 189 |
@request.session[:user_id] = 3 |
|
| 190 |
get :edit, :id => 2 |
|
| 191 |
assert_response :success |
|
| 192 |
assert_template 'edit' |
|
| 193 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 194 |
:name => 'query[is_public]' } |
|
| 195 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 196 |
:name => 'query_is_for_all', |
|
| 197 |
:checked => nil, |
|
| 198 |
:disabled => nil } |
|
| 199 |
end |
|
| 200 |
|
|
| 201 |
def test_edit_project_public_query |
|
| 202 |
@request.session[:user_id] = 2 |
|
| 203 |
get :edit, :id => 1 |
|
| 204 |
assert_response :success |
|
| 205 |
assert_template 'edit' |
|
| 206 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 207 |
:name => 'query[is_public]', |
|
| 208 |
:checked => 'checked' |
|
| 209 |
} |
|
| 210 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
| 211 |
:name => 'query_is_for_all', |
|
| 212 |
:checked => nil, |
|
| 213 |
:disabled => 'disabled' } |
|
| 214 |
end |
|
| 215 |
|
|
| 216 |
def test_edit_sort_criteria |
|
| 217 |
@request.session[:user_id] = 1 |
|
| 218 |
get :edit, :id => 5 |
|
| 219 |
assert_response :success |
|
| 220 |
assert_template 'edit' |
|
| 221 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
|
| 222 |
:child => { :tag => 'option', :attributes => { :value => 'priority',
|
|
| 223 |
:selected => 'selected' } } |
|
| 224 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
|
| 225 |
:child => { :tag => 'option', :attributes => { :value => 'desc',
|
|
| 226 |
:selected => 'selected' } } |
|
| 227 |
end |
|
| 228 |
|
|
| 229 |
def test_edit_invalid_query |
|
| 230 |
@request.session[:user_id] = 2 |
|
| 231 |
get :edit, :id => 99 |
|
| 232 |
assert_response 404 |
|
| 233 |
end |
|
| 234 |
|
|
| 235 |
def test_udpate_global_private_query |
|
| 236 |
@request.session[:user_id] = 3 |
|
| 237 |
put :update, |
|
| 238 |
:id => 3, |
|
| 239 |
:default_columns => '1', |
|
| 240 |
:fields => ["status_id", "assigned_to_id"], |
|
| 241 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
| 242 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
|
| 243 |
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
|
|
| 244 |
|
|
| 245 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
| 246 |
q = Query.find_by_name('test_edit_global_private_query')
|
|
| 247 |
assert !q.is_public? |
|
| 248 |
assert q.has_default_columns? |
|
| 249 |
assert q.valid? |
|
| 250 |
end |
|
| 251 |
|
|
| 252 |
def test_update_global_public_query |
|
| 253 |
@request.session[:user_id] = 1 |
|
| 254 |
put :update, |
|
| 255 |
:id => 4, |
|
| 256 |
:default_columns => '1', |
|
| 257 |
:fields => ["status_id", "assigned_to_id"], |
|
| 258 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
| 259 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
|
| 260 |
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
|
|
| 261 |
|
|
| 262 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
| 263 |
q = Query.find_by_name('test_edit_global_public_query')
|
|
| 264 |
assert q.is_public? |
|
| 265 |
assert q.has_default_columns? |
|
| 266 |
assert q.valid? |
|
| 267 |
end |
|
| 268 |
|
|
| 269 |
def test_update_with_failure |
|
| 270 |
@request.session[:user_id] = 1 |
|
| 271 |
put :update, :id => 4, :query => {:name => ''}
|
|
| 272 |
assert_response :success |
|
| 273 |
assert_template 'edit' |
|
| 274 |
end |
|
| 275 |
|
|
| 276 |
def test_destroy |
|
| 277 |
@request.session[:user_id] = 2 |
|
| 278 |
delete :destroy, :id => 1 |
|
| 279 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
| 280 |
assert_nil Query.find_by_id(1) |
|
| 281 |
end |
|
| 282 |
|
|
| 283 |
def test_backslash_should_be_escaped_in_filters |
|
| 284 |
@request.session[:user_id] = 2 |
|
| 285 |
get :new, :subject => 'foo/bar' |
|
| 286 |
assert_response :success |
|
| 287 |
assert_template 'new' |
|
| 288 |
assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body
|
|
| 289 |
end |
|
| 290 |
end |
|
| .svn/pristine/25/25a75439387b5e7c9157d74c8baba2d41c8319c0.svn-base | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<%= link_to l(:button_log_time), |
|
| 3 |
{:controller => 'timelog', :action => 'new', :project_id => @project, :issue_id => @issue},
|
|
| 4 |
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %> |
|
| 5 |
</div> |
|
| 6 |
|
|
| 7 |
<%= render_timelog_breadcrumb %> |
|
| 8 |
|
|
| 9 |
<h2><%= l(:label_spent_time) %></h2> |
|
| 10 |
|
|
| 11 |
<%= form_tag({:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue}, :method => :get, :id => 'query_form') do %>
|
|
| 12 |
<%= render :partial => 'date_range' %> |
|
| 13 |
<% end %> |
|
| 14 |
|
|
| 15 |
<div class="total-hours"> |
|
| 16 |
<p><%= l(:label_total_time) %>: <%= html_hours(l_hours(@total_hours)) %></p> |
|
| 17 |
</div> |
|
| 18 |
|
|
| 19 |
<% unless @entries.empty? %> |
|
| 20 |
<%= render :partial => 'list', :locals => { :entries => @entries }%>
|
|
| 21 |
<p class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></p> |
|
| 22 |
|
|
| 23 |
<% other_formats_links do |f| %> |
|
| 24 |
<%= f.link_to 'Atom', :url => params.merge({:issue_id => @issue, :key => User.current.rss_key}) %>
|
|
| 25 |
<%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
|
|
| 26 |
<% end %> |
|
| 27 |
|
|
| 28 |
<div id="csv-export-options" style="display:none;"> |
|
| 29 |
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3> |
|
| 30 |
<%= form_tag(params.slice(:project_id, :issue_id).merge(:format => 'csv', :page=>nil), :method => :get, :id => 'csv-export-form') do %> |
|
| 31 |
<%= query_hidden_tags @query %> |
|
| 32 |
<p> |
|
| 33 |
<label><%= radio_button_tag 'columns', '', true %> <%= l(:description_selected_columns) %></label><br /> |
|
| 34 |
<label><%= radio_button_tag 'columns', 'all' %> <%= l(:description_all_columns) %></label> |
|
| 35 |
</p> |
|
| 36 |
<p class="buttons"> |
|
| 37 |
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %> |
|
| 38 |
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> |
|
| 39 |
</p> |
|
| 40 |
<% end %> |
|
| 41 |
</div> |
|
| 42 |
<% end %> |
|
| 43 |
|
|
| 44 |
<% html_title l(:label_spent_time), l(:label_details) %> |
|
| 45 |
|
|
| 46 |
<% content_for :header_tags do %> |
|
| 47 |
<%= auto_discovery_link_tag(:atom, {:issue_id => @issue, :format => 'atom', :key => User.current.rss_key}, :title => l(:label_spent_time)) %>
|
|
| 48 |
<% end %> |
|
| .svn/pristine/25/25e20e75adcb2337c7b7589449cc334604a57456.svn-base | ||
|---|---|---|
| 1 |
# $Id: psw.rb 73 2006-04-24 21:59:35Z blackhedd $ |
|
| 2 |
# |
|
| 3 |
# |
|
| 4 |
#---------------------------------------------------------------------------- |
|
| 5 |
# |
|
| 6 |
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved. |
|
| 7 |
# |
|
| 8 |
# Gmail: garbagecat10 |
|
| 9 |
# |
|
| 10 |
# This program is free software; you can redistribute it and/or modify |
|
| 11 |
# it under the terms of the GNU General Public License as published by |
|
| 12 |
# the Free Software Foundation; either version 2 of the License, or |
|
| 13 |
# (at your option) any later version. |
|
| 14 |
# |
|
| 15 |
# This program is distributed in the hope that it will be useful, |
|
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 |
# GNU General Public License for more details. |
|
| 19 |
# |
|
| 20 |
# You should have received a copy of the GNU General Public License |
|
| 21 |
# along with this program; if not, write to the Free Software |
|
| 22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 23 |
# |
|
| 24 |
#--------------------------------------------------------------------------- |
|
| 25 |
# |
|
| 26 |
# |
|
| 27 |
|
|
| 28 |
|
|
| 29 |
module Net |
|
| 30 |
class LDAP |
|
| 31 |
|
|
| 32 |
|
|
| 33 |
class Password |
|
| 34 |
class << self |
|
| 35 |
|
|
| 36 |
# Generate a password-hash suitable for inclusion in an LDAP attribute. |
|
| 37 |
# Pass a hash type (currently supported: :md5 and :sha) and a plaintext |
|
| 38 |
# password. This function will return a hashed representation. |
|
| 39 |
# STUB: This is here to fulfill the requirements of an RFC, which one? |
|
| 40 |
# TODO, gotta do salted-sha and (maybe) salted-md5. |
|
| 41 |
# Should we provide sha1 as a synonym for sha1? I vote no because then |
|
| 42 |
# should you also provide ssha1 for symmetry? |
|
| 43 |
def generate( type, str ) |
|
| 44 |
case type |
|
| 45 |
when :md5 |
|
| 46 |
require 'md5' |
|
| 47 |
"{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }"
|
|
| 48 |
when :sha |
|
| 49 |
require 'sha1' |
|
| 50 |
"{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }"
|
|
| 51 |
# when ssha |
|
| 52 |
else |
|
| 53 |
raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
|
|
| 54 |
end |
|
| 55 |
end |
|
| 56 |
|
|
| 57 |
end |
|
| 58 |
end |
|
| 59 |
|
|
| 60 |
|
|
| 61 |
end # class LDAP |
|
| 62 |
end # module Net |
|
| 63 |
|
|
| 64 |
|
|
| .svn/pristine/25/25e2b9b227cb6f18e371c2b9f54071b5c31827f3.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class Redmine::CipheringTest < ActiveSupport::TestCase |
|
| 21 |
|
|
| 22 |
def test_password_should_be_encrypted |
|
| 23 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 24 |
r = Repository::Subversion.generate!(:password => 'foo') |
|
| 25 |
assert_equal 'foo', r.password |
|
| 26 |
assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) |
|
| 27 |
end |
|
| 28 |
end |
|
| 29 |
|
|
| 30 |
def test_password_should_be_clear_with_blank_key |
|
| 31 |
Redmine::Configuration.with 'database_cipher_key' => '' do |
|
| 32 |
r = Repository::Subversion.generate!(:password => 'foo') |
|
| 33 |
assert_equal 'foo', r.password |
|
| 34 |
assert_equal 'foo', r.read_attribute(:password) |
|
| 35 |
end |
|
| 36 |
end |
|
| 37 |
|
|
| 38 |
def test_password_should_be_clear_with_nil_key |
|
| 39 |
Redmine::Configuration.with 'database_cipher_key' => nil do |
|
| 40 |
r = Repository::Subversion.generate!(:password => 'foo') |
|
| 41 |
assert_equal 'foo', r.password |
|
| 42 |
assert_equal 'foo', r.read_attribute(:password) |
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
|
|
| 46 |
def test_blank_password_should_be_clear |
|
| 47 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 48 |
r = Repository::Subversion.generate!(:password => '') |
|
| 49 |
assert_equal '', r.password |
|
| 50 |
assert_equal '', r.read_attribute(:password) |
|
| 51 |
end |
|
| 52 |
end |
|
| 53 |
|
|
| 54 |
def test_unciphered_password_should_be_readable |
|
| 55 |
Redmine::Configuration.with 'database_cipher_key' => nil do |
|
| 56 |
r = Repository::Subversion.generate!(:password => 'clear') |
|
| 57 |
end |
|
| 58 |
|
|
| 59 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 60 |
r = Repository.first(:order => 'id DESC') |
|
| 61 |
assert_equal 'clear', r.password |
|
| 62 |
end |
|
| 63 |
end |
|
| 64 |
|
|
| 65 |
def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered |
|
| 66 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 67 |
r = Repository::Subversion.generate!(:password => 'clear') |
|
| 68 |
end |
|
| 69 |
|
|
| 70 |
Redmine::Configuration.with 'database_cipher_key' => '' do |
|
| 71 |
r = Repository.first(:order => 'id DESC') |
|
| 72 |
# password can not be deciphered |
|
| 73 |
assert_nothing_raised do |
|
| 74 |
assert r.password.match(/\Aaes-256-cbc:.+\Z/) |
|
| 75 |
end |
|
| 76 |
end |
|
| 77 |
end |
|
| 78 |
|
|
| 79 |
def test_encrypt_all |
|
| 80 |
Repository.delete_all |
|
| 81 |
Redmine::Configuration.with 'database_cipher_key' => nil do |
|
| 82 |
Repository::Subversion.generate!(:password => 'foo') |
|
| 83 |
Repository::Subversion.generate!(:password => 'bar') |
|
| 84 |
end |
|
| 85 |
|
|
| 86 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 87 |
assert Repository.encrypt_all(:password) |
|
| 88 |
r = Repository.first(:order => 'id DESC') |
|
| 89 |
assert_equal 'bar', r.password |
|
| 90 |
assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) |
|
| 91 |
end |
|
| 92 |
end |
|
| 93 |
|
|
| 94 |
def test_decrypt_all |
|
| 95 |
Repository.delete_all |
|
| 96 |
Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
|
| 97 |
Repository::Subversion.generate!(:password => 'foo') |
|
| 98 |
Repository::Subversion.generate!(:password => 'bar') |
|
| 99 |
|
|
| 100 |
assert Repository.decrypt_all(:password) |
|
| 101 |
r = Repository.first(:order => 'id DESC') |
|
| 102 |
assert_equal 'bar', r.password |
|
| 103 |
assert_equal 'bar', r.read_attribute(:password) |
|
| 104 |
end |
|
| 105 |
end |
|
| 106 |
end |
|
| .svn/pristine/25/25f1da6f66db9d07326385e2039be298e7f220f8.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class Redmine::ConfigurationTest < ActiveSupport::TestCase |
|
| 21 |
def setup |
|
| 22 |
@conf = Redmine::Configuration |
|
| 23 |
end |
|
| 24 |
|
|
| 25 |
def test_empty |
|
| 26 |
assert_kind_of Hash, load_conf('empty.yml', 'test')
|
|
| 27 |
end |
|
| 28 |
|
|
| 29 |
def test_default |
|
| 30 |
assert_kind_of Hash, load_conf('default.yml', 'test')
|
|
| 31 |
assert_equal 'foo', @conf['somesetting'] |
|
| 32 |
end |
|
| 33 |
|
|
| 34 |
def test_no_default |
|
| 35 |
assert_kind_of Hash, load_conf('no_default.yml', 'test')
|
|
| 36 |
assert_equal 'foo', @conf['somesetting'] |
|
| 37 |
end |
|
| 38 |
|
|
| 39 |
def test_overrides |
|
| 40 |
assert_kind_of Hash, load_conf('overrides.yml', 'test')
|
|
| 41 |
assert_equal 'bar', @conf['somesetting'] |
|
| 42 |
end |
|
| 43 |
|
|
| 44 |
def test_with |
|
| 45 |
load_conf('default.yml', 'test')
|
|
| 46 |
assert_equal 'foo', @conf['somesetting'] |
|
| 47 |
@conf.with 'somesetting' => 'bar' do |
|
| 48 |
assert_equal 'bar', @conf['somesetting'] |
|
| 49 |
end |
|
| 50 |
assert_equal 'foo', @conf['somesetting'] |
|
| 51 |
end |
|
| 52 |
|
|
| 53 |
private |
|
| 54 |
|
|
| 55 |
def load_conf(file, env) |
|
| 56 |
@conf.load( |
|
| 57 |
:file => File.join(Rails.root, 'test', 'fixtures', 'configuration', file), |
|
| 58 |
:env => env |
|
| 59 |
) |
|
| 60 |
end |
|
| 61 |
end |
|
Also available in: Unified diff