blob: ad128208175b9805f33d5490d54650076e0d7800 [file] [log] [blame]
eroman751d1792014-08-26 06:57:201// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Blink Reformata30d4232018-04-07 15:31:065#include "components/webcrypto/status.h"
eroman751d1792014-08-26 06:57:206#include "base/stl_util.h"
erg56f12322015-04-17 00:51:487#include "components/webcrypto/algorithm_dispatch.h"
eroman7bcd6a72015-09-16 02:41:218#include "components/webcrypto/algorithms/test_helpers.h"
erg56f12322015-04-17 00:51:489#include "components/webcrypto/crypto_data.h"
Blink Reformata30d4232018-04-07 15:31:0610#include "third_party/blink/public/platform/web_crypto_algorithm.h"
11#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
12#include "third_party/blink/public/platform/web_crypto_key_algorithm.h"
eroman751d1792014-08-26 06:57:2013
eroman751d1792014-08-26 06:57:2014namespace webcrypto {
15
16namespace {
17
18// Tests several Status objects against their expected hard coded values, as
19// well as ensuring that comparison of Status objects works.
20// Comparison should take into account both the error details, as well as the
21// error type.
22TEST(WebCryptoStatusTest, Basic) {
23 // Even though the error message is the same, these should not be considered
24 // the same by the tests because the error type is different.
25 EXPECT_NE(Status::DataError(), Status::OperationError());
26 EXPECT_NE(Status::Success(), Status::OperationError());
27
28 EXPECT_EQ(Status::Success(), Status::Success());
eroman398e7e12014-11-08 03:05:1029 EXPECT_EQ(Status::ErrorJwkMemberWrongType("kty", "string"),
30 Status::ErrorJwkMemberWrongType("kty", "string"));
eroman751d1792014-08-26 06:57:2031
32 Status status = Status::Success();
33
34 EXPECT_FALSE(status.IsError());
35 EXPECT_EQ("", status.error_details());
36
37 status = Status::OperationError();
38 EXPECT_TRUE(status.IsError());
39 EXPECT_EQ("", status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5440 EXPECT_EQ(blink::kWebCryptoErrorTypeOperation, status.error_type());
eroman751d1792014-08-26 06:57:2041
42 status = Status::DataError();
43 EXPECT_TRUE(status.IsError());
44 EXPECT_EQ("", status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5445 EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
eroman751d1792014-08-26 06:57:2046
47 status = Status::ErrorUnsupported();
48 EXPECT_TRUE(status.IsError());
49 EXPECT_EQ("The requested operation is unsupported", status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5450 EXPECT_EQ(blink::kWebCryptoErrorTypeNotSupported, status.error_type());
eroman751d1792014-08-26 06:57:2051
eroman398e7e12014-11-08 03:05:1052 status = Status::ErrorJwkMemberMissing("kty");
eroman751d1792014-08-26 06:57:2053 EXPECT_TRUE(status.IsError());
eroman8c565ba2014-12-10 20:59:0654 EXPECT_EQ("The required JWK member \"kty\" was missing",
eroman751d1792014-08-26 06:57:2055 status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5456 EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
eroman751d1792014-08-26 06:57:2057
eroman398e7e12014-11-08 03:05:1058 status = Status::ErrorJwkMemberWrongType("kty", "string");
eroman751d1792014-08-26 06:57:2059 EXPECT_TRUE(status.IsError());
eroman8c565ba2014-12-10 20:59:0660 EXPECT_EQ("The JWK member \"kty\" must be a string", status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5461 EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
eroman751d1792014-08-26 06:57:2062
63 status = Status::ErrorJwkBase64Decode("n");
64 EXPECT_TRUE(status.IsError());
eroman8c565ba2014-12-10 20:59:0665 EXPECT_EQ(
66 "The JWK member \"n\" could not be base64url decoded or contained "
67 "padding",
68 status.error_details());
Blink Reformat1c4d759e2017-04-09 16:34:5469 EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
eroman751d1792014-08-26 06:57:2070}
71
72} // namespace
73
74} // namespace webcrypto