src/tests/persistent_volume_endpoints_tests.cpp
// This tests that an attempt to create or destroy a volume with bad
// credentials results in an 'Unauthorized' HTTP error.
This tests that an attempt to create or destroy a volume with bad
credentials results in an 'Unauthorized' HTTP error.
This tests that an attempt to create or destroy a volume with bad credentials results in an ' Unauthorized ' HTTP error .
TEST_F(PersistentVolumeEndpointsTest, BadCredentials)
{
  TestAllocator<> allocator;
  EXPECT_CALL(allocator, initialize(_, _, _, _));
  Try<Owned<cluster::Master>> master = StartMaster(&allocator);
  ASSERT_SOME(master);
  Future<SlaveID> slaveId;
  EXPECT_CALL(allocator, addSlave(_, _, _, _, _))
    .WillOnce(DoAll(InvokeAddSlave(&allocator),
                    FutureArg<0>(&slaveId)));
  slave::Flags slaveFlags = CreateSlaveFlags();
  slaveFlags.resources = "disk(role1):1024";
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
  ASSERT_SOME(slave);
  Credential credential;
  credential.set_principal("bad-principal");
  credential.set_secret("bad-secret");
  Resources volume = createPersistentVolume(
      Megabytes(64),
      "role1",
      "id1",
      "path1");
  process::http::Headers headers = createBasicAuthHeaders(credential);
  string body = createRequestBody(slaveId.get(), "volumes", volume);
  Future<Response> response =
    process::http::post(master.get()->pid, "create-volumes", headers, body);
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(
      Unauthorized({}).status,
      response);
  response =
    process::http::post(master.get()->pid, "destroy-volumes", headers, body);
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(
      Unauthorized({}).status,
      response);
}
TEST_F ( PersistentVolumeEndpointsTest , BadCredentials ) { TestAllocator < > allocator ; EXPECT_CALL ( allocator , initialize ( _ , _ , _ , _ ) ) ; Try < Owned < cluster :: Master > > master = StartMaster ( & allocator ) ; ASSERT_SOME ( master ) ; Future < SlaveID > slaveId ; EXPECT_CALL ( allocator , addSlave ( _ , _ , _ , _ , _ ) ) . WillOnce ( DoAll ( InvokeAddSlave ( & allocator ) , FutureArg < 0 > ( & slaveId ) ) ) ; slave :: Flags slaveFlags = CreateSlaveFlags ( ) ; slaveFlags . resources = " " ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) , slaveFlags ) ; ASSERT_SOME ( slave ) ; Credential credential ; credential . set_principal ( " " ) ; credential . set_secret ( " " ) ; Resources volume = createPersistentVolume ( Megabytes ( 64 ) , " " , " " , " " ) ; process :: http :: Headers headers = createBasicAuthHeaders ( credential ) ; string body = createRequestBody ( slaveId . get ( ) , " " , volume ) ; Future < Response > response = process :: http :: post ( master . get ( ) -> pid , " " , headers , body ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( Unauthorized ( { } ) . status , response ) ; response = process :: http :: post ( master . get ( ) -> pid , " " , headers , body ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( Unauthorized ( { } ) . status , response ) ; }
This tests that an attempt to create or destroy a volume with bad
credentials results in an 'Unauthorized' HTTP error.
This tests that an attempt to create or destroy a volume with bad credentials results in an ' Unauthorized ' HTTP error .