code
stringlengths
23
2.05k
label_name
stringlengths
6
7
label
int64
0
37
def test_create_valid AuthSourceLdap.any_instance.stubs(:valid?).returns(true) post :create, {:auth_source_ldap => {:name => AuthSourceLdap.first.name}}, set_session_user assert_redirected_to auth_source_ldaps_url end
CWE-200
10
def remove_all delete = Protocol::Delete.new( operation.database, operation.collection, operation.selector ) session.with(consistency: :strong) do |session| session.execute delete end end
CWE-20
0
it "creates an index with the provided name" do indexes.create(key, name: "custom_index_name") indexes[key]["name"].should eq "custom_index_name" end
CWE-400
2
def login(username, password) session.cluster.login(name, username, password) end
CWE-400
2
def initialize(database, command) super database, :$cmd, command, limit: -1 end
CWE-400
2
it "stores the cluster" do session.cluster.should be_a(Moped::Cluster) end
CWE-20
0
it "removes the stored credentials" do cluster.logout :admin cluster.auth.should be_empty end
CWE-20
0
it "should should be a subclass of Base" do Puppet::FileServing::Content.superclass.should equal(Puppet::FileServing::Base) end
CWE-200
10
it 'correctly exports the CategoryUser table' do data, _csv_out = make_component_csv expect(data.find { |r| r['category_id'] == category.id }).to be_nil expect(data.length).to eq(4) data.sort! { |a, b| a['category_id'].to_i <=> b['category_id'].to_i } expect(data[0][:category_id]).to eq(subcategory.id.to_s) expect(data[0][:notification_level].to_s).to eq('tracking') expect(DateTime.parse(data[0][:dismiss_new_timestamp])).to eq(reset_at) expect(data[1][:category_id]).to eq(subsubcategory.id.to_s) expect(data[1][:category_names]).to eq("#{category.name}|#{subcategory.name}|#{subsubcategory.name}") expect(data[1][:notification_level]).to eq('regular') expect(DateTime.parse(data[1][:dismiss_new_timestamp])).to eq(reset_at) expect(data[2][:category_id]).to eq(announcements.id.to_s) expect(data[2][:category_names]).to eq(announcements.name) expect(data[2][:notification_level]).to eq('watching_first_post') expect(data[2][:dismiss_new_timestamp]).to eq('') expect(data[3][:category_names]).to eq(data[3][:category_id]) end
CWE-200
10
def logout session.cluster.logout(name) end
CWE-20
0
it "should choose :rest when a server is specified" do @request.stubs(:protocol).returns "puppet" @request.expects(:server).returns "foo" @object.select_terminus(@request).should == :rest end
CWE-200
10
it "delegates to the current database" do database = mock(Moped::Database) session.should_receive(:current_database).and_return(database) database.should_receive(:drop) session.drop end
CWE-20
0
it "does not drop other indexes" do indexes[age: -1].should_not be_nil end
CWE-400
2
def each documents = query @query_op documents.each { |doc| yield doc } while more? return kill if limited? && @get_more_op.limit <= 0 documents = query @get_more_op documents.each { |doc| yield doc } end end
CWE-400
2
it "unmemoizes the current database" do db = session.current_database session.with(new_options) do |new_session| new_session.current_database.should_not eql db end end
CWE-20
0
it "instructs the cluster to reconnect" do session.stub(with: new_session) new_session.cluster.should_receive(:reconnect) session.new(new_options) end
CWE-400
2
it "returns a hex string representation of the id" do Moped::BSON::ObjectId.new(bytes).to_s.should eq "4e4d66343b39b68407000001" end
CWE-400
2
it "creates an index with the provided name" do indexes.create(key, name: "custom_index_name") indexes[key]["name"].should eq "custom_index_name" end
CWE-20
0
def test_update_valid SmartProxy.any_instance.stubs(:valid?).returns(true) put :update, {:id => SmartProxy.first,:smart_proxy => {:url => "http://elsewhere.com:8443"}}, set_session_user assert_equal "http://elsewhere.com:8443", SmartProxy.first.url assert_redirected_to smart_proxies_url end
CWE-200
10
it "stores the collection" do query.collection.should eq collection end
CWE-20
0
def remove delete = Protocol::Delete.new( operation.database, operation.collection, operation.selector, flags: [:remove_first] ) session.with(consistency: :strong) do |session| session.execute delete end end
CWE-400
2
it "executes a simple query" do session.should_receive(:simple_query).with(query.operation) query.one end
CWE-20
0
it "doesn't log in the user when not approved" do SiteSetting.must_approve_users = true get "/session/email-login/#{email_token.token}" expect(response.status).to eq(200) expect(CGI.unescapeHTML(response.body)).to include( I18n.t("login.not_approved") ) end
CWE-287
4
it "requires an account with mail" do user = FactoryGirl.create(:user) get :index, {}, set_session_user.merge(:user => user.id) assert_response :redirect assert_redirected_to edit_user_path(user) assert_equal "An email address is required, please update your account details", flash[:error] end
CWE-200
10
def __bson_load__(io) new io.read(12).unpack('C*') end
CWE-400
2
it "allows you to create an account and redeems the invite successfully even if must_approve_users is enabled" do SiteSetting.must_approve_users = true login_with_sso_and_invite expect(response.status).to eq(302) expect(response).to redirect_to("/") expect(invite.reload.redeemed?).to eq(true) user = User.find_by_email("[email protected]") expect(user.active).to eq(true) end
CWE-863
11
def initialize(seeds, options = {}) @cluster = Cluster.new(seeds) @options = options @options[:consistency] ||= :eventual end
CWE-400
2
def test_destroy subnet = Subnet.first subnet.hosts.clear subnet.interfaces.clear subnet.domains.clear delete :destroy, {:id => subnet}, set_session_user assert_redirected_to subnets_url assert !Subnet.exists?(subnet.id) end
CWE-200
10
def dup session = super session.instance_variable_set :@options, options.dup if defined? @current_database session.send(:remove_instance_variable, :@current_database) end session end
CWE-400
2
it "doesn't try to set flags" do session.stub(socket_for: socket) expect { session.query(query) }.not_to raise_exception end
CWE-400
2
def each documents = query @query_op documents.each { |doc| yield doc } while more? return kill if limited? && @get_more_op.limit <= 0 documents = query @get_more_op documents.each { |doc| yield doc } end end
CWE-20
0
it "returns true" do Moped::BSON::ObjectId.new(bytes).should == Moped::BSON::ObjectId.new(bytes) end
CWE-20
0
def initialize(remote_host, remote_port, local_host = nil, local_port = nil) if Thread.current[:private_address_check] && PrivateAddressCheck.resolves_to_private_address?(remote_host) raise PrivateAddressCheck::PrivateConnectionAttemptedError end initialize_without_private_address_check(remote_host, remote_port, local_host, local_port) end
CWE-362
18
it "updates to a mongo advanced selector" do query.explain query.operation.selector.should eq( "$query" => selector, "$explain" => true, "$orderby" => { _id: 1 } ) end
CWE-400
2
it "updates all records matching selector with change" do query.should_receive(:update).with(change, [:multi]) query.update_all change end
CWE-400
2
it "updates a hostgroup with a parent parameter" do child = FactoryGirl.create(:hostgroup, :parent => @base) as_admin do assert_equal "original", child.parameters["x"] end post :update, {"id" => child.id, "hostgroup" => {"name" => child.name, :group_parameters_attributes => {"0" => {:name => "x", :value =>"overridden", :_destroy => ""}}}}, set_session_user assert_redirected_to hostgroups_url child.reload assert_equal "overridden", child.parameters["x"] end
CWE-200
10
it "sets the query operation's fields" do query.select(a: 1) query.operation.fields.should eq(a: 1) end
CWE-20
0
it "raises an exception" do expect { session.current_database }.to raise_exception end
CWE-400
2
it "raises no exception" do lambda do cluster.sync_server server end.should_not raise_exception end
CWE-400
2
def build_query(path, details) query = @pattern.dup query.gsub!(/\:prefix(\/)?/, path.prefix.empty? ? "" : "#{path.prefix}\\1") # prefix can be empty... query.gsub!(/\:action/, path.partial? ? "_#{path.name}" : path.name) details.each do |ext, variants| query.gsub!(/\:#{ext}/, "{#{variants.compact.uniq.join(',')}}") end File.expand_path(query, @path) end
CWE-20
0
def verify_active_session if !request.post? && params[:status].blank? && User.exists?(session[:user].presence) warning _("You have already logged in") redirect_back_or_to hosts_path return end end
CWE-200
10
it "creates an index" do indexes.create(key, background: true) indexes[key]["background"].should eq true end
CWE-20
0
it "sets the object id's data" do Moped::BSON::ObjectId.new(bytes).data.should == bytes end
CWE-400
2
def create_clamp_code(nbits, signed) if signed == :signed max = (1 << (nbits - 1)) - 1 min = -(max + 1) else max = (1 << nbits) - 1 min = 0 end "val = (val < #{min}) ? #{min} : (val > #{max}) ? #{max} : val" end
CWE-400
2
def deliver!(mail) envelope_from = mail.return_path || mail.sender || mail.from_addrs.first return_path = "-f " + '"' + envelope_from.escape_for_shell + '"' if envelope_from arguments = [settings[:arguments], return_path].compact.join(" ") self.class.call(settings[:location], arguments, mail.destinations.collect(&:shellescape).join(" "), mail) end
CWE-20
0
it "does not re-sync the cluster" do cluster.should_receive(:sync).never cluster.socket_for :write end
CWE-400
2
def crop_command target = @attachment.instance if target.cropping?(@attachment.name) w = target.send :"#{@attachment.name}_crop_w" h = target.send :"#{@attachment.name}_crop_h" x = target.send :"#{@attachment.name}_crop_x" y = target.send :"#{@attachment.name}_crop_y" ["-crop", "#{w}x#{h}+#{x}+#{y}"] end end
CWE-20
0
it "returns a hex string representation of the id" do Moped::BSON::ObjectId.new(bytes).to_s.should eq "4e4d66343b39b68407000001" end
CWE-20
0
it "sets the generation time" do time = Time.at((Time.now.utc - 64800).to_i).utc Moped::BSON::ObjectId.new(nil, time).generation_time.should == time end
CWE-20
0
it "re-enabled functionality if whitelisted" do Rack::MiniProfiler.config.authorization_mode = :whitelist expect(Rack::MiniProfiler).to receive(:request_authorized?) { true }.twice get '/html?pp=enable' last_response.body.should include('/mini-profiler-resources/includes.js') end
CWE-200
10
def kill session.execute kill_cursor_op end
CWE-20
0
it "returns false" do indexes.drop(other: 1).should be_false end
CWE-20
0
it "returns the query" do query.limit(5).should eql query end
CWE-400
2
it "has an empty list of servers" do cluster.servers.should be_empty end
CWE-400
2
def simple_query(query) query.limit = -1 query(query).documents.first end
CWE-400
2
def selected_ids return @selected_ids if @selected_ids ids = default_ids_hash #types NOT ignored - get ids that are selected hash_keys.each do |col| ids[col] = Array(taxonomy.send(col)) end #types that ARE ignored - get ALL ids for object Array(taxonomy.ignore_types).each do |taxonomy_type| ids["#{taxonomy_type.tableize.singularize}_ids"] = taxonomy_type.constantize.pluck(:id) end ids["#{opposite_taxonomy_type}_ids"] = Array(taxonomy.send("#{opposite_taxonomy_type}_ids")) @selected_ids = ids end
CWE-200
10
def seed # Authorisation is disabled usually when run from a rake db:* task User.current = FactoryGirl.build(:user, :admin => true) load File.expand_path('../../../../db/seeds.rb', __FILE__) end
CWE-200
10
def with_taxonomy_scope(loc = Location.current, org = Organization.current, inner_method = :subtree_ids) self.which_ancestry_method = inner_method self.which_location = Location.expand(loc) if SETTINGS[:locations_enabled] self.which_organization = Organization.expand(org) if SETTINGS[:organizations_enabled] scope = block_given? ? yield : where('1=1') scope = scope_by_taxable_ids(scope) scope.readonly(false) end
CWE-200
10
def deliver!(mail) envelope_from = mail.return_path || mail.sender || mail.from_addrs.first return_path = "-f \"#{envelope_from.to_s.gsub('"', '\"')}\"" if envelope_from arguments = [settings[:arguments], return_path].compact.join(" ") Sendmail.call(settings[:location], arguments, mail.destinations.collect(&:shellescape).join(" "), mail) end
CWE-20
0
def user_with_viewer_rights_should_fail_to_edit_a_domain setup_users get :edit, {:id => Domain.first.id} assert @response.status == '403 Forbidden' end
CWE-200
10
it "should be created correctly" do invite = Fabricate(:invite, email: '[email protected]') user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'walter', name: 'Walter White') expect(user.username).to eq('walter') expect(user.name).to eq('Walter White') expect(user.email).to eq('[email protected]') expect(user.approved).to eq(true) expect(user.active).to eq(false) end
CWE-863
11
it "has an empty list of dynamic seeds" do cluster.dynamic_seeds.should be_empty end
CWE-400
2
it "raises an OperationFailure exception" do session.stub(socket_for: socket) socket.stub(execute: reply) expect { session.execute(operation) }.to raise_exception(Moped::Errors::OperationFailure) end
CWE-400
2
def remove delete = Protocol::Delete.new( operation.database, operation.collection, operation.selector, flags: [:remove_first] ) session.with(consistency: :strong) do |session| session.execute delete end end
CWE-20
0
it "approves pending record" do reviewable = ReviewableUser.needs_review!(target: Fabricate(:user, email: invite.email), created_by: invite.invited_by) reviewable.status = Reviewable.statuses[:pending] reviewable.save! invite_redeemer.redeem reviewable.reload expect(reviewable.status).to eq(Reviewable.statuses[:approved]) end
CWE-863
11
it "executes the operation on the master node" do session.should_receive(:socket_for).with(:write). and_return(socket) socket.should_receive(:execute).with(operation) session.execute(operation) end
CWE-400
2
it "executes a count command" do database.should_receive(:command).with( count: collection.name, query: selector ).and_return("n" => 4) query.count end
CWE-20
0
def remote_address @request.forwarded_for || socket_address rescue Exception log_error nil end
CWE-20
0
it "merges the old and new session's options" do session.with(new_options) do |new_session| new_session.options.should eq options.merge(new_options) end end
CWE-20
0
it "should choose :file_server when the settings name is 'puppet' and no server is specified" do modules = mock 'modules' @request.expects(:protocol).returns "puppet" @request.expects(:server).returns nil Puppet.settings.expects(:value).with(:name).returns "puppet" @object.select_terminus(@request).should == :file_server end
CWE-200
10
it "yields a new session" do session.with(new_options) do |new_session| new_session.should_not eql session end end
CWE-400
2
it "fails when user is suspended" do user.update!( suspended_till: 2.days.from_now, suspended_at: Time.zone.now ) get "/session/email-login/#{email_token.token}" expect(response.status).to eq(200) expect(CGI.unescapeHTML(response.body)).to include(I18n.t("login.suspended", date: I18n.l(user.suspended_till, format: :date_only) )) end
CWE-287
4
it "returns the new session" do session.stub(with: new_session) session.new(new_options).should eql new_session end
CWE-20
0
it 'should return a second factor prompt' do get "/session/email-login/#{email_token.token}" expect(response.status).to eq(200) response_body = CGI.unescapeHTML(response.body) expect(response_body).to include(I18n.t( "login.second_factor_title" )) expect(response_body).to_not include(I18n.t( "login.invalid_second_factor_code" )) end
CWE-287
4
def new(options = {}) session = with(options) session.cluster.reconnect if block_given? yield session else session end end
CWE-400
2
it "can set the password and ip_address" do password = 's3cure5tpasSw0rD' ip_address = '192.168.1.1' invite = Fabricate(:invite, email: '[email protected]') user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'walter', name: 'Walter White', password: password, ip_address: ip_address) expect(user).to have_password expect(user.confirm_password?(password)).to eq(true) expect(user.approved).to eq(true) expect(user.ip_address).to eq(ip_address) expect(user.registration_ip_address).to eq(ip_address) end
CWE-863
11
def test_parse_bigger xml = <<-XML.strip_heredoc <request id="1027" creator="Iggy"> <action type="submit"> <source project="home:Iggy" package="TestPack" rev="1"/> <target project="kde4" package="mypackage"/> <options> <sourceupdate>cleanup</sourceupdate> </options> <acceptinfo rev="1" srcmd5="806a6e27ed7915d1bb8d8a989404fd5a" osrcmd5="d41d8cd98f00b204e9800998ecf8427e"/> </action> <priority>critical</priority> <state name="review" who="Iggy" when="2012-11-07T21:13:12"> <comment>No comment</comment> </state> <review state="new" when="2017-09-01T09:11:11" by_user="adrian"/> <review state="new" when="2017-09-01T09:11:11" by_group="test_group"/> <review state="accepted" when="2012-11-07T21:13:12" who="tom" by_user="tom"> <comment>review1</comment> </review> <review state="new" when="2012-11-07T21:13:13" who="tom" by_user="tom"> <comment>please accept</comment> </review> <description>Left blank</description> </request> XML req = BsRequest.new_from_xml(xml) req.save! # number got increased by one assert_equal 1027, req.number newxml = req.render_xml assert_equal xml, newxml wi = req.webui_infos(diffs: false) # iggy is *not* target maintainer assert_equal false, wi['is_target_maintainer'] assert_equal wi['actions'][0], type: :submit, sprj: 'home:Iggy', spkg: 'TestPack', srev: '1', tprj: 'kde4', tpkg: 'mypackage', name: 'Submit TestPack' end
CWE-862
8
it "stores the collection name" do collection.name.should eq :users end
CWE-400
2
it "sets the query operation's skip field" do query.skip(5) query.operation.skip.should eq 5 end
CWE-400
2
def login(username, password) session.cluster.login(name, username, password) end
CWE-20
0
def legal?(string) string.to_s =~ /^[0-9a-f]{24}$/i ? true : false end
CWE-400
2
def execute(op) mode = options[:consistency] == :eventual ? :read : :write socket = socket_for(mode) if safe? last_error = Protocol::Command.new( "admin", { getlasterror: 1 }.merge(safety) ) socket.execute(op, last_error).documents.first.tap do |result| raise Errors::OperationFailure.new( op, result ) if result["err"] || result["errmsg"] end else socket.execute(op) end end
CWE-400
2
it "executes the operation on a slave node" do session.should_receive(:socket_for).with(:read). and_return(socket) socket.should_receive(:execute).with(operation) session.execute(operation) end
CWE-400
2
it "returns an enumerator" do cursor = mock(Moped::Cursor) Moped::Cursor.stub(new: cursor) query.each.should be_a Enumerator end
CWE-20
0
it 'does not log in with incorrect two factor' do post "/session/email-login/#{email_token.token}", params: { second_factor_token: "0000", second_factor_method: UserSecondFactor.methods[:totp] } expect(response.status).to eq(200) expect(CGI.unescapeHTML(response.body)).to include(I18n.t( "login.invalid_second_factor_code" )) end
CWE-287
4
it "changes the $orderby" do query.sort(a: 1) query.sort(a: 2) query.operation.selector.should eq( "$query" => selector, "$orderby" => { a: 2 } ) end
CWE-20
0
def legal?(str) !!str.match(/^[0-9a-f]{24}$/i) end
CWE-20
0
it "returns the living socket" do cluster.socket_for(:write).should eq socket end
CWE-20
0
def test_jail_instances_should_have_limited_methods expected = ["class", "inspect", "method_missing", "methods", "respond_to?", "respond_to_missing?", "to_jail", "to_s", "instance_variable_get"] expected.delete('respond_to_missing?') if RUBY_VERSION > '1.9.3' # respond_to_missing? is private in rubies above 1.9.3 objects.each do |object| assert_equal expected.sort, reject_pretty_methods(object.to_jail.methods.map(&:to_s).sort) end end
CWE-200
10
it "stores whether the connection is direct" do cluster.direct.should be_true end
CWE-20
0
def test_private_address assert_raises PrivateAddressCheck::PrivateConnectionAttemptedError do PrivateAddressCheck.only_public_connections do TCPSocket.new("localhost", 80) end end end
CWE-362
18
it "creates an index with a generated name" do indexes.create(key) indexes[key]["name"].should eq "location.latlong_2d_name_1_age_-1" end
CWE-400
2
def generation_time Time.at(@data.pack("C4").unpack("N")[0]).utc end
CWE-400
2
def secondaries servers.select(&:secondary?) end
CWE-20
0
it "executes the operation on the master node" do session.should_receive(:socket_for).with(:write). and_return(socket) socket.should_receive(:execute).with(operation) session.execute(operation) end
CWE-20
0
it "queries the master node" do session.should_receive(:socket_for).with(:write). and_return(socket) session.query(query) end
CWE-20
0
it "has an empty list of secondaries" do cluster.secondaries.should be_empty end
CWE-20
0
def primaries servers.select(&:primary?) end
CWE-400
2
def test_AES_crush 500.times do assert_nothing_raised("[Bug #2768]") do # it caused OpenSSL SEGV by uninitialized key OpenSSL::Cipher::AES128.new("ECB").update "." * 17 end end end
CWE-326
9
def to_s @@string_format % data end
CWE-400
2