<commit_before>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.crypto.hash',
  name: 'HashableTest',
  extends: 'foam.nanos.test.Test',

  javaImports: [
    'foam.nanos.auth.User',
    'org.bouncycastle.util.encoders.Hex',
    'java.security.NoSuchAlgorithmException'
  ],

  methods: [
    {
      name: 'runTest',
      javaCode: `
        User input = new User.Builder(x)
          .setId(1000)
          .setFirstName("Foam")
          .setLastName("Test")
          .setEmail("<EMAIL>")
          .build();

        // non-chained hash with correct digest
        Hashable_HashWithValidAlgorithm(input, "MD5",
/*
            "d41d8cd98f00b204e9800998ecf8427e");
        Hashable_HashWithValidAlgorithm(input, "SHA-1",
            "da39a3ee5e6b4b0d3255bfef95601890afd80709");
        Hashable_HashWithValidAlgorithm(input, "SHA-256",
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
        Hashable_HashWithValidAlgorithm(input, "SHA-384",
            "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
        Hashable_HashWithValidAlgorithm(input, "SHA-512",
            "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
*/
            "6a6e70ca62d7e0afbde550202cf27bae");
        Hashable_HashWithValidAlgorithm(input, "SHA-1",
            "8ff96b7d123909fe97ecbdfc40059f43d06cb52a");
        Hashable_HashWithValidAlgorithm(input, "SHA-256",
            "9d4aa9f2ed968ba8a1b16bfbc4242a4d9f64df358ca11be051fd80c322c2ffff");
        Hashable_HashWithValidAlgorithm(input, "SHA-384",
            "fd6d5cbb17477742f4b4680d0d5f17940d7c180d56313d6570947f1674e2f0f04c9721e5af0383192d9e6dde7690e0b4");
        Hashable_HashWithValidAlgorithm(input, "SHA-512",
            "1d033a412e9db056510d5a5421bcb576e4feb9a9b7dba88e5c90ab396cb2e4f31028d7e00a8c0422b683de7ba2f309b7a898e9b761817f7e674670710f8ea5b6");

        // hashing same objects produces same digest
        Hashable_HashingSameObjects_ProducesSameDigest(input, input,
            "Hashing the same object produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input.fclone(), input,
            "Hashing the same object where the first object is fcloned produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input, input.fclone(),
            "Hashing the same object where the second object is fcloned produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input.fclone(), input.fclone(),
            "Hashing the same object where both objects are fcloned produces the same digest");

        // hash with invalid algorithm
        Hashable_HashWithInvalidAlgorithm_NoSuchAlgorithmException(input);<commit_msg>revert User hashes, as this branch explicitly sets includeInDigest and storageOptional<commit_after>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.crypto.hash',
  name: 'HashableTest',
  extends: 'foam.nanos.test.Test',

  javaImports: [
    'foam.nanos.auth.User',
    'org.bouncycastle.util.encoders.Hex',
    'java.security.NoSuchAlgorithmException'
  ],

  methods: [
    {
      name: 'runTest',
      javaCode: `
        User input = new User.Builder(x)
          .setId(1000)
          .setFirstName("Foam")
          .setLastName("Test")
          .setEmail("<EMAIL>")
          .build();

        // non-chained hash with correct digest
        Hashable_HashWithValidAlgorithm(input, "MD5",
            "d41d8cd98f00b204e9800998ecf8427e");
        Hashable_HashWithValidAlgorithm(input, "SHA-1",
            "da39a3ee5e6b4b0d3255bfef95601890afd80709");
        Hashable_HashWithValidAlgorithm(input, "SHA-256",
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
        Hashable_HashWithValidAlgorithm(input, "SHA-384",
            "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
        Hashable_HashWithValidAlgorithm(input, "SHA-512",
            "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
        // hashing same objects produces same digest
        Hashable_HashingSameObjects_ProducesSameDigest(input, input,
            "Hashing the same object produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input.fclone(), input,
            "Hashing the same object where the first object is fcloned produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input, input.fclone(),
            "Hashing the same object where the second object is fcloned produces the same digest");
        Hashable_HashingSameObjects_ProducesSameDigest(input.fclone(), input.fclone(),
            "Hashing the same object where both objects are fcloned produces the same digest");

        // hash with invalid algorithm
        Hashable_HashWithInvalidAlgorithm_NoSuchAlgorithmException(input);
{'fraction_non_alphanumeric': 0.08550752237669015, 'fraction_numerical': 0.13730717958484098, 'mean_word_length': 3.6519043401240037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922027', 'n_tokens_mistral': 2188, 'n_tokens_neox': 1843, 'n_words': 268}