mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
minor changes
This commit is contained in:
parent
961441672f
commit
bcdda46857
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This is a poorly written jsonnet file. Given to the formatter executable will be changed into a canonical jsonnet file form.
|
||||
local b = import "somefile.libsonnet"; # comment
|
||||
local a = import "differentfile.libsonnet"; // another comment in different style
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This is a jsonnet code which evaluates to mutliple output files.
|
||||
{
|
||||
"first_file.json": {
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This is a jsonnet code which evaluates to json file, which can be interpreted as YAML stream.
|
||||
local
|
||||
first_object = {
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
class JsonnetSapiSandbox : public JsonnetSandbox {
|
||||
public:
|
||||
explicit JsonnetSapiSandbox(std::string in_file, std::string out_directory)
|
||||
: in_file_(std::move(in_file)), out_directory_(std::move(out_directory)) {}
|
||||
: in_file_(std::move(in_file)),
|
||||
out_directory_(std::move(out_directory)) {}
|
||||
|
||||
// We need a slightly different policy than the default one
|
||||
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
|
||||
|
@ -42,7 +43,8 @@ class JsonnetSapiSandbox : public JsonnetSandbox {
|
|||
__NR_futex,
|
||||
__NR_close,
|
||||
})
|
||||
.AddDirectoryAt(sandbox2::file::CleanPath(&out_directory_[0]), "/output",
|
||||
.AddDirectoryAt(sandbox2::file::CleanPath(&out_directory_[0]),
|
||||
"/output",
|
||||
/*is_ro=*/false)
|
||||
.AddDirectoryAt(dirname(&in_file_[0]), "/input", true)
|
||||
.BuildOrDie();
|
||||
|
|
|
@ -70,8 +70,8 @@ int main(int argc, char* argv[]) {
|
|||
sapi::v::RemotePtr output_pointer(output.value());
|
||||
sapi::StatusOr<bool> success;
|
||||
|
||||
success = api.c_write_output_stream(&output_pointer,
|
||||
out_file_var.PtrBefore());
|
||||
success =
|
||||
api.c_write_output_stream(&output_pointer, out_file_var.PtrBefore());
|
||||
CHECK(success.ok() && success.value())
|
||||
<< "Writing to output file failed " << success.status() << " "
|
||||
<< success.value();
|
||||
|
|
|
@ -12,17 +12,19 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "jsonnet_base_sandbox.h"
|
||||
#include "jsonnet_sapi.sapi.h"
|
||||
#include "sandboxed_api/util/flag.h"
|
||||
#include "sandboxed_api/util/status_matchers.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
class JsonnetTestHelper {
|
||||
protected:
|
||||
|
@ -32,7 +34,8 @@ class JsonnetTestHelper {
|
|||
void TestTearDown();
|
||||
|
||||
void Read_input(char* filename);
|
||||
void Evaluate_jsonnet_code(char* filename, Evaluation type, bool expected_correct);
|
||||
void Evaluate_jsonnet_code(char* filename, Evaluation type,
|
||||
bool expected_correct);
|
||||
void Write_output(char* filename_or_directory, Evaluation type);
|
||||
std::string Read_output(char* filename);
|
||||
|
||||
|
@ -45,5 +48,4 @@ class JsonnetTestHelper {
|
|||
std::string input_filename_in_sandboxee;
|
||||
bool if_jsonnet_vm_was_used;
|
||||
bool if_input_was_read;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user