Merge pull request #3098 from duckduckgo/mintsoft/rc4-template

RC4: Converting to text template
master
Ben Moon 2016-06-08 18:55:42 +01:00
commit fcd84610c3
2 changed files with 23 additions and 17 deletions

View File

@ -43,11 +43,14 @@ handle remainder => sub {
return;
}
return "$operation: $plaintext, with key: $key is $result",
structured_answer => {
operation => $operation,
input => [html_enc($plaintext) . ", Key: $key"],
result => $result
return "$operation: $plaintext, with key: $key is $result", structured_answer => {
data => {
title => html_enc($result),
subtitle => "$operation: " . html_enc($plaintext) . ", Key: ".html_enc($key)
},
templates => {
group => 'text'
}
};
};

27
t/Rc4.t
View File

@ -9,22 +9,25 @@ use DDG::Test::Goodie;
zci answer_type => "rc4";
zci is_cached => 1;
sub build_test {
my ($direction, $input, $key, $answer) = @_;
return test_zci("RC4 $direction: $input, with key: $key is $answer", structured_answer => {
data => {
title => $answer,
subtitle => "RC4 $direction: $input, Key: $key"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test(
[qw(
DDG::Goodie::Rc4
)],
'rc4 en mysecretkey hello' => test_zci("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=",
structured_answer => {
input => ['hello, Key: mysecretkey'],
operation => "RC4 Encrypt",
result => "grYU1K8="
}),
'rc4 de duck yWrJniG/nNg=' => test_zci("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks",
structured_answer => {
input => ['yWrJniG/nNg=, Key: duck'],
operation => "RC4 Decrypt",
result => "DdgRocks"
}),
'rc4 en mysecretkey hello' => build_test("Encrypt", "hello", "mysecretkey", "grYU1K8="),
'rc4 de duck yWrJniG/nNg=' => build_test("Decrypt", "yWrJniG/nNg=", "duck", "DdgRocks"),
'rc4 ' => undef,
'rc4 enc missing' => undef,
'rc4 no operation' => undef