<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

require "rack/test"
require "director"

describe Bosh::Director::Controller do
  include Rack::Test::Methods

  before(:each) do
    @temp_dir = Dir.mktmpdir
    FileUtils.mkdir_p(@temp_dir)
    test_config = YAML.load(spec_asset("test-director-config.yml"))
    test_config["dir"] = @temp_dir
    Bosh::Director::Config.configure(test_config)
  end

  after(:each) do
    FileUtils.rm_rf(@temp_dir)
  end

  def app
    @app ||= Bosh::Director::Controller.new
  end

  def login_as_admin
    basic_authorize "admin", "admin"
  end

  def login_as(username, password)
    basic_authorize username, password
  end

  def expect_redirect_to_queued_task(response)
    response.should be_redirect

    (last_response.location =~ /\/tasks\/(\d+)/).should_not be_nil

    new_task = Bosh::Director::Models::Task[$1]
    new_task.state.should == "queued"
  end

  it "requires auth" do
    get "/"
    last_response.status.should == 401
  end

  it "allows Basic HTTP Auth with admin/admin credentials for test purposes (even though user doesn't exist)" do
    basic_authorize "admin", "admin"
    get "/"
    last_response.status.should == 404
  end

  describe "Fetching status" do

    it "not authenticated" do
      get "/info"
      last_response.status.should == 200
      Yajl::Parser.parse(last_response.body)["user"].should == nil
    end

    it "authenticated" do
      login_as_admin
      get "/info"

      last_response.status.should == 200
      expected = {
        "name"    => "Test Director",
        "version" => Bosh::Director::VERSION,
        "user"    => "admin"
      }
      last_response.body.should == Yajl::Encoder.encode(expected)
    end

  end

  describe "API calls" do
    before(:each) { login_as_admin }

    describe "creating a stemcell" do
      it "expects compressed stemcell file" do
        post "/stemcells", {}, { "CONTENT_TYPE" => "application/x-compressed", :input => spec_asset("tarball.tgz") }
        expect_redirect_to_queued_task(last_response)
      end

      it "only consumes application/x-compressed" do
        post "/stemcells", {}, { "CONTENT_TYPE" => "application/octet-stream", :input => spec_asset("tarball.tgz") }
        last_response.status.should == 404
      end
    end

    describe "creating a release" do
      it "expects compressed release file" do
        post "/releases", {}, { "CONTENT_TYPE" => "application/x-compressed", :input => spec_asset("tarball.tgz") }
        expect_redirect_to_queued_task(last_response)
      end
<commit_msg>add test for UUID<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

require "rack/test"
require "director"

describe Bosh::Director::Controller do
  include Rack::Test::Methods

  before(:each) do
    @temp_dir = Dir.mktmpdir
    FileUtils.mkdir_p(@temp_dir)
    test_config = YAML.load(spec_asset("test-director-config.yml"))
    test_config["dir"] = @temp_dir
    Bosh::Director::Config.configure(test_config)
  end

  after(:each) do
    FileUtils.rm_rf(@temp_dir)
  end

  def app
    @app ||= Bosh::Director::Controller.new
  end

  def login_as_admin
    basic_authorize "admin", "admin"
  end

  def login_as(username, password)
    basic_authorize username, password
  end

  def expect_redirect_to_queued_task(response)
    response.should be_redirect

    (last_response.location =~ /\/tasks\/(\d+)/).should_not be_nil

    new_task = Bosh::Director::Models::Task[$1]
    new_task.state.should == "queued"
  end

  it "requires auth" do
    get "/"
    last_response.status.should == 401
  end

  it "allows Basic HTTP Auth with admin/admin credentials for test purposes (even though user doesn't exist)" do
    basic_authorize "admin", "admin"
    get "/"
    last_response.status.should == 404
  end

  describe "Fetching status" do

    it "not authenticated" do
      get "/info"
      last_response.status.should == 200
      Yajl::Parser.parse(last_response.body)["user"].should == nil
    end

    it "authenticated" do
      login_as_admin
      get "/info"

      last_response.status.should == 200
      expected = {
        "name"    => "Test Director",
        "version" => Bosh::Director::VERSION,
        "uuid"    => Bosh::Director::Config.uuid,
        "user"    => "admin"
      }
      last_response.body.should == Yajl::Encoder.encode(expected)
    end

  end

  describe "API calls" do
    before(:each) { login_as_admin }

    describe "creating a stemcell" do
      it "expects compressed stemcell file" do
        post "/stemcells", {}, { "CONTENT_TYPE" => "application/x-compressed", :input => spec_asset("tarball.tgz") }
        expect_redirect_to_queued_task(last_response)
      end

      it "only consumes application/x-compressed" do
        post "/stemcells", {}, { "CONTENT_TYPE" => "application/octet-stream", :input => spec_asset("tarball.tgz") }
        last_response.status.should == 404
      end
    end

    describe "creating a release" do
      it "expects compressed release file" do
        post "/releases", {}, { "CONTENT_TYPE" => "application/x-compressed", :input => spec_asset("tarball.tgz") }
        expect_redirect_to_queued_task(last_response)
      end

{'fraction_non_alphanumeric': 0.12442396313364056, 'fraction_numerical': 0.006144393241167435, 'mean_word_length': 3.150597609561753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '367318', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1632, 'n_words': 371}