code
stringlengths
23
2.05k
label_name
stringlengths
6
7
label
int64
0
37
def has_cookie? !@cookie.nil? end
CWE-200
10
def drop command dropDatabase: 1 end
CWE-400
2
def process_invitation approve_account_if_needed add_to_private_topics_if_invited add_user_to_groups send_welcome_message notify_invitee end
CWE-863
11
def test_jail_classes_should_have_limited_methods expected = ["new", "methods", "name", "inherited", "method_added", "inspect", "allow", "allowed?", "allowed_methods", "init_allowed_methods", "<", # < needed in Rails Object#subclasses_of "ancestors", "==" # ancestor...
CWE-200
10
def new(options = {}) session = with(options) session.cluster.reconnect if block_given? yield session else session end end
CWE-20
0
it "returns the index with the provided key" do indexes[name: 1]["name"].should eq "name_1" end
CWE-400
2
it "removes the socket" do cluster.should_receive(:remove).with(dead_server) cluster.socket_for :write end
CWE-400
2
it "only aquires the socket once" do session.cluster.should_receive(:socket_for). with(:read).once.and_return(mock(Moped::Socket)) session.send(:socket_for, :read) session.send(:socket_for, :read) end
CWE-400
2
it "returns true" do session.should be_safe end
CWE-400
2
it "adds the credentials to the auth cache" do cluster.login("admin", "username", "password") cluster.auth.should eq("admin" => ["username", "password"]) end
CWE-400
2
it "stores the list of seeds" do cluster.seeds.should eq ["127.0.0.1:27017", "127.0.0.1:27018"] end
CWE-400
2
def access?(query) return false if record.internal == true && !user.permissions?('ticket.agent') ticket = Ticket.lookup(id: record.ticket_id) Pundit.authorize(user, ticket, query) end
CWE-862
8
it "returns true" do session.should be_safe end
CWE-20
0
def test_destroy domain = Domain.first domain.hosts.clear domain.hostgroups.clear domain.subnets.clear delete :destroy, {:id => domain}, set_session_user assert_redirected_to domains_url assert !Domain.exists?(domain.id) end
CWE-200
10
it "sets the query operation's limit field" do query.limit(5) query.operation.limit.should eq 5 end
CWE-20
0
def test_should_not_destroy_if_used_by_hosts subnet = subnets(:one) delete :destroy, {:id => subnet}, set_session_user assert_redirected_to subnets_url assert Subnet.exists?(subnet.id) end
CWE-200
10
def self.new_from_xml_hash(hash) r = Review.new r.state = hash.delete('state') { raise ArgumentError, 'no state' } r.state = r.state.to_sym r.by_user = hash.delete('by_user') r.by_group = hash.delete('by_group') r.by_project = hash.delete('by_project') r.by_package = hash.delete('by_pack...
CWE-862
8
it "has an empty list of secondaries" do cluster.secondaries.should be_empty end
CWE-400
2
def insert(documents) documents = [documents] unless documents.is_a? Array insert = Protocol::Insert.new(database.name, name, documents) database.session.with(consistency: :strong) do |session| session.execute insert end end
CWE-400
2
it "updates to a mongo advanced selector" do query.explain query.operation.selector.should eq( "$query" => selector, "$explain" => true, "$orderby" => { _id: 1 } ) end
CWE-20
0
def test_update_invalid put :update, {:id => Hostgroup.first, :hostgroup => { :name => '' }}, set_session_user assert_template 'edit' end
CWE-200
10
def test_update_invalid Medium.any_instance.stubs(:valid?).returns(false) put :update, {:id => Medium.first, :medium => {:name => nil}}, set_session_user assert_template 'edit' end
CWE-200
10
it "executes a count command" do database.should_receive(:command).with( count: collection.name, query: selector ).and_return("n" => 4) query.count end
CWE-400
2
it "returns only published articles" do article = create(:article) create(:comment, article: article) unpublished_article = create(:article, state: "draft") create(:comment, article: unpublished_article) expect(described_class.published).to eq([article]) expect(described_class.be...
CWE-863
11
def initialize # Generate and cache 3 bytes of identifying information from the current # machine. @machine_id = Digest::MD5.digest(Socket.gethostname).unpack("C3") @mutex = Mutex.new @last_timestamp = nil @counter = 0 end
CWE-400
2
def socket_for(mode) sync unless primaries.any? || (secondaries.any? && mode == :read) server = nil while primaries.any? || (secondaries.any? && mode == :read) if mode == :write || secondaries.empty? server = primaries.sample else server = secondaries.sample ...
CWE-20
0
def write!(headers) if @orig_disable_profiling != @disable_profiling || @orig_backtrace_level != @backtrace_level || @cookie.nil? settings = {"p" => "t" } settings["dp"] = "t" if @disable_profiling settings["bt"] = @backtrace_level if @backtrace_level ...
CWE-200
10
it 'returns success' do get "/session/email-login/#{email_token.token}" expect(response).to redirect_to("/") end
CWE-287
4
it "returns the database from the options" do session.current_database.should eq(database) end
CWE-400
2
def reactions_given params.require(:username) user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts)) raise Discourse::NotFound unless guardian.can_see_profile?(user) reaction_users = DiscourseReactions::ReactionUser...
CWE-200
10
it "inserts the documents" do session.should_receive(:execute).with do |insert| insert.documents.should eq [{a: 1}, {b: 2}] end collection.insert([{a: 1}, {b: 2}]) end
CWE-400
2
def set_inboxes @inbox_ids = if params[:inbox_id] current_account.inboxes.where(id: params[:inbox_id]) else @current_user.assigned_inboxes.pluck(:id) end
CWE-269
6
it 'returns the right response' do get "/session/email-login/adasdad" expect(response.status).to eq(200) expect(CGI.unescapeHTML(response.body)).to match( I18n.t('email_login.invalid_token') ) end
CWE-287
4
it "initializes with the strings bytes" do Moped::BSON::ObjectId.should_receive(:new).with(bytes) Moped::BSON::ObjectId.from_string "4e4d66343b39b68407000001" end
CWE-400
2
def restrict_user_fields?(user) user.trust_level == TrustLevel[0] && anonymous? end
CWE-200
10
def more? @get_more_op.cursor_id != 0 end
CWE-400
2
def check_action_permission!(skip_source = nil) super(skip_source) # only perform the following check, if we are called from # BsRequest.permission_check_change_state! (that is, if # skip_source is set to true). Always executing this check # would be a regression, because this code is also execute...
CWE-732
13
it "should return :file if the URI protocol is set to 'file'" do @request.expects(:protocol).returns "file" @object.select_terminus(@request).should == :file end
CWE-200
10
it "does not change the original session's options" do original_options = options.dup session.with(new_options) do |new_session| session.options.should eql original_options end end
CWE-400
2
it 'returns success' do get "/session/email-login/#{email_token.token}" expect(response).to redirect_to("/") end
CWE-287
4
it "limits the query" do session.should_receive(:query) do |query| query.limit.should eq(-1) reply end session.simple_query(query) end
CWE-20
0
def legal?(str) !!str.match(/^[0-9a-f]{24}$/i) end
CWE-400
2
def kill session.execute kill_cursor_op end
CWE-400
2
it "creates a new cursor" do cursor = mock(Moped::Cursor, next: nil) Moped::Cursor.should_receive(:new). with(session, query.operation).and_return(cursor) query.each end
CWE-400
2
def handle_meta(message, local, &callback) method = Channel.parse(message['channel'])[1] unless META_METHODS.include?(method) response = make_response(message) response['error'] = Faye::Error.channel_forbidden(message['channel']) response['successful'] = false return cal...
CWE-287
4
it "inserts the document" do session.should_receive(:execute).with do |insert| insert.documents.should eq [{a: 1}] end collection.insert(a: 1) end
CWE-20
0
it "returns a new Query" do Moped::Query.should_receive(:new). with(collection, selector).and_return(query) collection.find(selector).should eq query end
CWE-20
0
def update article = Ticket::Article.find(params[:id]) authorize!(article) clean_params = Ticket::Article.association_name_to_id_convert(params) clean_params = Ticket::Article.param_cleanup(clean_params, true) # only apply preferences changes (keep not updated keys/values) clean_params = art...
CWE-862
8
def known_addresses [].tap do |addresses| addresses.concat seeds addresses.concat dynamic_seeds addresses.concat servers.map { |server| server.address } end.uniq end
CWE-20
0
def initialize(env) request = ::Rack::Request.new(env) @cookie = request.cookies[COOKIE_NAME] if @cookie @cookie.split(",").map{|pair| pair.split("=")}.each do |k,v| @orig_disable_profiling = @disable_profiling = (v=='t') if k == "dp" @backtrace_level = v....
CWE-200
10
def write_key_to_disk(key, identity) # Writing is disabled. Don't bother checking any other states. return unless lookup_config_option('learn_public_keys') =~ /^1|y/ publickey_dir = lookup_config_option('publickey_dir') unless publickey_dir Log.info("Public key sent wi...
CWE-20
0
def next now = Time.new.to_i counter = @mutex.synchronize do last_timestamp, @last_timestamp = @last_timestamp, now if last_timestamp == now @counter += 1 else @counter = 0 end end generate(now...
CWE-400
2
it "removes the first matching document" do session.should_receive(:with, :consistency => :strong). and_yield(session) session.should_receive(:execute).with do |delete| delete.flags.should eq [:remove_first] delete.selector.should eq query.operation.selector end que...
CWE-400
2
it "does not drop other indexes" do indexes[age: -1].should_not be_nil end
CWE-20
0
def legal?(string) string.to_s =~ /^[0-9a-f]{24}$/i ? true : false end
CWE-400
2
def test_update_valid Realm.any_instance.stubs(:valid?).returns(true) put :update, {:id => Realm.first.name, :realm => { :realm_proxy_id => SmartProxy.first.id } }, set_session_user assert_equal SmartProxy.first.id, Realm.first.realm_proxy_id assert_redirected_to realms_url end
CWE-200
10
it 'does not include user or group archived messages' do UserArchivedMessage.archive!(user.id, group_message) UserArchivedMessage.archive!(user.id, private_message) topics = TopicQuery.new(nil).list_private_messages_all(user).topics expect(topics).to eq([]) GroupArchivedMessage.arch...
CWE-863
11
it "has an empty list of servers" do cluster.servers.should be_empty end
CWE-20
0
it "sets the query operation's limit field" do query.limit(5) query.operation.limit.should eq 5 end
CWE-400
2
def current_user User.except_hidden.find_by_login(self.user) end
CWE-200
10
def generate(time, inc = 0) pid = Process.pid % 0xFFFF [ time >> 24 & 0xFF, # 4 bytes time (network order) time >> 16 & 0xFF, time >> 8 & 0xFF, time & 0xFF, @machine_id[0], # 3 bytes machine @machine_id[1], ...
CWE-20
0
it "should return :file if the request key is fully qualified" do @request.expects(:key).returns File.expand_path('/foo') @object.select_terminus(@request).should == :file end
CWE-200
10
it "removes all matching documents" do session.should_receive(:with, :consistency => :strong). and_yield(session) session.should_receive(:execute).with do |delete| delete.flags.should eq [] delete.selector.should eq query.operation.selector end query.remove_all ...
CWE-20
0
def show_article auto_discovery_feed respond_to do |format| format.html do @comment = Comment.new @page_title = this_blog.article_title_template.to_title(@article, this_blog, params) @description = this_blog.article_desc_template.to_title(@article, this_blog, params) @ke...
CWE-863
11
def merge(server) previous = servers.find { |other| other == server } primary = server.primary? secondary = server.secondary? if previous previous.merge(server) else servers << server end end
CWE-20
0
it 'fails when local logins via email is disabled' do SiteSetting.enable_local_logins_via_email = false get "/session/email-login/#{email_token.token}" expect(response.status).to eq(404) end
CWE-287
4
def test_formats_valid AuthSourceLdap.any_instance.stubs(:valid?).returns(false) put :update, {:id => AuthSourceLdap.first.id, :format => "weird", :auth_source_ldap => {:name => AuthSourceLdap.first.name} }, set_session_user assert_response :success wierd_id = "#{AuthSourceLdap.first.id}.weird" p...
CWE-200
10
it "stores whether the connection is direct" do cluster.direct.should be_true end
CWE-400
2
it "removes the socket" do cluster.should_receive(:remove).with(dead_server) cluster.socket_for :write end
CWE-20
0
it 'fails when local logins is disabled' do SiteSetting.enable_local_logins = false get "/session/email-login/#{email_token.token}" expect(response.status).to eq(500) end
CWE-287
4
def reset_password @admin_user = Motor::AdminUser.find(params[:admin_user_id]) authorize!(:manage, @admin_user) Devise::Mailer.default_url_options = { host: request.host, protocol: request.protocol, port: request.port } @admin_user.send_reset_password_instructions head :ok end
CWE-116
15
def private_messages_for(user, type) options = @options options.reverse_merge!(per_page: per_page_setting) result = Topic.includes(:allowed_users) result = result.includes(:tags) if SiteSetting.tagging_enabled if type == :group result = result.joins( "INNER JOIN top...
CWE-863
11
def remove(server) servers.delete(server) end
CWE-400
2
def simple_query(query) query.limit = -1 query(query).documents.first end
CWE-20
0
it "does not change the original session's options" do original_options = options.dup session.with(new_options) do |new_session| session.options.should eql original_options end end
CWE-20
0
it "updates all records matching selector with change" do query.should_receive(:update).with(change, [:multi]) query.update_all change end
CWE-20
0
it "does not activate user invited via links" do invite = Fabricate(:invite, email: 'walter.white@email.com', emailed_status: Invite.emailed_status_types[:not_required]) user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'walter', name: 'Walter White') ex...
CWE-863
11
it "should escape evil haxxor attemptes" do Mail.defaults do delivery_method :sendmail, :arguments => nil end mail = Mail.new do from '"foo\";touch /tmp/PWNED;\""@blah.com' to 'marcel@test.lindsaar.net' subject 'invalid RFC2822' end Mail::Sendmail.should_r...
CWE-20
0
def index @applications = Doorkeeper.config.application_model.authorized_for(current_resource_owner) respond_to do |format| format.html format.json { render json: @applications } end end
CWE-862
8
def test_destroy auth_source_ldap = AuthSourceLdap.first User.where(:auth_source_id => auth_source_ldap.id).update_all(:auth_source_id => nil) delete :destroy, {:id => auth_source_ldap}, set_session_user assert_redirected_to auth_source_ldaps_url assert !AuthSourceLdap.exists?(auth_source_ldap.id)...
CWE-200
10
def private_messages_for(user, type) options = @options options.reverse_merge!(per_page: per_page_setting) result = Topic.includes(:allowed_users) result = result.includes(:tags) if SiteSetting.tagging_enabled if type == :group result = result.joins( "INNER JOIN top...
CWE-863
11
it "initializes with the strings bytes" do Moped::BSON::ObjectId.should_receive(:new).with(bytes) Moped::BSON::ObjectId.from_string "4e4d66343b39b68407000001" end
CWE-20
0
def create @application = Doorkeeper.config.application_model.new(application_params) if @application.save flash[:notice] = I18n.t(:notice, scope: %i[doorkeeper flash applications create]) flash[:application_secret] = @application.plaintext_secret respond_to do |format| ...
CWE-862
8
it "delegates to the cluster" do session.cluster.should_receive(:socket_for).with(:read) session.send(:socket_for, :read) end
CWE-20
0
def reconnect @servers = servers.map { |server| Server.new(server.address) } end
CWE-400
2
it 'should not overwrite an existing file if overwrite_stored_key is not set' do @plugin.stubs(:lookup_config_option).with('learn_public_keys').returns('1') @plugin.stubs(:lookup_config_option).with('publickey_dir').returns('ssh/pkd') @plugin.stubs(:lookup_config_option).with('over...
CWE-20
0
it "returns the living socket" do cluster.socket_for(:write).should eq socket end
CWE-400
2
it "returns false" do session.should_not be_safe end
CWE-400
2
def match?(name, ip) ip? ? pattern.include?(IPAddr.new(ip)) : matchname?(name) end
CWE-287
4
it "yields a session" do session.with(new_options) do |new_session| new_session.should be_a Moped::Session end end
CWE-20
0
def test_nest get :nest, {:id => Hostgroup.first.id}, set_session_user assert_template 'new' end
CWE-200
10
it "recognizes and generates #destroy" do { :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1") end
CWE-200
10
it "inserts the document" do session.should_receive(:execute).with do |insert| insert.documents.should eq [{a: 1}] end collection.insert(a: 1) end
CWE-400
2
it "returns the document" do session.simple_query(query).should eq(a: 1) end
CWE-20
0
it "returns the same hash" do Moped::BSON::ObjectId.new(bytes).hash.should eq Moped::BSON::ObjectId.new(bytes).hash end
CWE-400
2
it "recognizes and generates #index" do { :get => "/users" }.should route_to(:controller => "users", :action => "index") end
CWE-200
10
def initialize(seeds, options = {}) @cluster = Cluster.new(seeds) @options = options @options[:consistency] ||= :eventual end
CWE-20
0
it "stores the selector" do query.selector.should eq selector end
CWE-20
0
it "memoizes the database" do database = session.current_database session.current_database.should equal(database) end
CWE-20
0
def __bson_dump__(io, key) io << Types::OBJECT_ID io << key io << NULL_BYTE io << data.pack('C12') end
CWE-20
0