Skip to content

Commit 6711c32

Browse files
committed
Add tests for the new iframes option
Why is this change needed? -------------------------- We want to have a basic check that this new works and continues to work in the future. How does it address the issue? ------------------------------ Add iframes tests. Any links to any relevant tickets, articles, or other resources? --------------------------------------------------------------- https://3.basecamp.com/3093825/buckets/29007795/todolists/5257298600 Did you complete all of the following? -------------------------------------- - Run test suite? - Add new tests? - Consider security implications and practices?
1 parent 022e59d commit 6711c32

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

script/inside_container/test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ cd "$(dirname "$0")/../.."
44

55
# script/build
66

7+
apt update
8+
apt install poppler-utils -y
9+
710
# runs a test file with PASS/FAIL message
811
run_test() {
912
export TEST_NAME="$(basename "$1")"

test/iframes_default.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using DocRaptor.Client;
2+
using DocRaptor.Model;
3+
using DocRaptor.Api;
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Threading;
8+
using System.Diagnostics;
9+
10+
class SyncTest {
11+
static void Main(string[] args) {
12+
DocApi docraptor = new DocApi();
13+
docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
14+
// docraptor.Configuration.Debug = true; // Not supported in Csharp
15+
16+
// Default value of prince_options[iframes]
17+
Doc doc = new Doc(
18+
name: "csharp-iframes.pdf",
19+
test: true,
20+
documentContent: "" +
21+
"<html><body>" +
22+
"<p>Baseline text</p>" +
23+
"<iframe src=\"https://docraptor-test-harness.herokuapp.com/public/index.html\"></iframe>" +
24+
"</body></html>",
25+
documentType: Doc.DocumentTypeEnum.Pdf
26+
);
27+
28+
byte[] document = docraptor.CreateDoc(doc);
29+
string output_file = Environment.GetEnvironmentVariable("TEST_OUTPUT_DIR") +
30+
"/" + Environment.GetEnvironmentVariable("TEST_NAME") + "_csharp_" +
31+
Environment.GetEnvironmentVariable("RUNTIME_ENV") + ".pdf";
32+
File.WriteAllBytes(output_file, document);
33+
34+
string command = "pdftotext " + output_file + " -";
35+
var proc = new Process
36+
{
37+
StartInfo = new ProcessStartInfo
38+
{
39+
FileName = "/bin/bash",
40+
Arguments = "-c \""+ command + "\"",
41+
UseShellExecute = false,
42+
RedirectStandardOutput = true,
43+
CreateNoWindow = true
44+
}
45+
};
46+
proc.Start();
47+
string output = proc.StandardOutput.ReadToEnd();
48+
proc.WaitForExit();
49+
50+
if(!output.Contains("Test")) {
51+
Console.WriteLine("output should have contained iframe content: " + output);
52+
Environment.Exit(1);
53+
}
54+
}
55+
}

test/iframes_false.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using DocRaptor.Client;
2+
using DocRaptor.Model;
3+
using DocRaptor.Api;
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Threading;
8+
using System.Diagnostics;
9+
10+
class SyncTest {
11+
static void Main(string[] args) {
12+
DocApi docraptor = new DocApi();
13+
docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
14+
// docraptor.Configuration.Debug = true; // Not supported in Csharp
15+
16+
Doc doc = new Doc(
17+
name: "csharp-iframes.pdf",
18+
test: true,
19+
documentContent: "" +
20+
"<html><body>" +
21+
"<p>Baseline text</p>" +
22+
"<iframe src=\"https://docraptor-test-harness.herokuapp.com/public/index.html\"></iframe>" +
23+
"</body></html>",
24+
documentType: Doc.DocumentTypeEnum.Pdf,
25+
princeOptions: new PrinceOptions(
26+
iframes: false
27+
)
28+
);
29+
30+
byte[] document = docraptor.CreateDoc(doc);
31+
string output_file = Environment.GetEnvironmentVariable("TEST_OUTPUT_DIR") +
32+
"/" + Environment.GetEnvironmentVariable("TEST_NAME") + "_csharp_" +
33+
Environment.GetEnvironmentVariable("RUNTIME_ENV") + ".pdf";
34+
File.WriteAllBytes(output_file, document);
35+
36+
string command = "pdftotext " + output_file + " -";
37+
var proc = new Process
38+
{
39+
StartInfo = new ProcessStartInfo
40+
{
41+
FileName = "/bin/bash",
42+
Arguments = "-c \""+ command + "\"",
43+
UseShellExecute = false,
44+
RedirectStandardOutput = true,
45+
CreateNoWindow = true
46+
}
47+
};
48+
proc.Start();
49+
string output = proc.StandardOutput.ReadToEnd();
50+
proc.WaitForExit();
51+
52+
if(output.Contains("Test")) {
53+
Console.WriteLine("output shouldn't have contained iframe content: " + output);
54+
Environment.Exit(1);
55+
}
56+
}
57+
}

test/iframes_true.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using DocRaptor.Client;
2+
using DocRaptor.Model;
3+
using DocRaptor.Api;
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Threading;
8+
using System.Diagnostics;
9+
10+
class SyncTest {
11+
static void Main(string[] args) {
12+
DocApi docraptor = new DocApi();
13+
docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
14+
// docraptor.Configuration.Debug = true; // Not supported in Csharp
15+
16+
Doc doc = new Doc(
17+
name: "csharp-iframes.pdf",
18+
test: true,
19+
documentContent: "" +
20+
"<html><body>" +
21+
"<p>Baseline text</p>" +
22+
"<iframe src=\"https://docraptor-test-harness.herokuapp.com/public/index.html\"></iframe>" +
23+
"</body></html>",
24+
documentType: Doc.DocumentTypeEnum.Pdf,
25+
princeOptions: new PrinceOptions(
26+
iframes: true
27+
)
28+
);
29+
30+
byte[] document = docraptor.CreateDoc(doc);
31+
string output_file = Environment.GetEnvironmentVariable("TEST_OUTPUT_DIR") +
32+
"/" + Environment.GetEnvironmentVariable("TEST_NAME") + "_csharp_" +
33+
Environment.GetEnvironmentVariable("RUNTIME_ENV") + ".pdf";
34+
File.WriteAllBytes(output_file, document);
35+
36+
string command = "pdftotext " + output_file + " -";
37+
var proc = new Process
38+
{
39+
StartInfo = new ProcessStartInfo
40+
{
41+
FileName = "/bin/bash",
42+
Arguments = "-c \""+ command + "\"",
43+
UseShellExecute = false,
44+
RedirectStandardOutput = true,
45+
CreateNoWindow = true
46+
}
47+
};
48+
proc.Start();
49+
string output = proc.StandardOutput.ReadToEnd();
50+
proc.WaitForExit();
51+
52+
if(!output.Contains("Test")) {
53+
Console.WriteLine("output should have contained iframe content: " + output);
54+
Environment.Exit(1);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)