<commit_before># Copyright 2016, Cossack Labs Limited
#
# 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.
# coding: utf-8
import socket
import json
import time
import os
import random
import string
import subprocess
import unittest
from base64 import b64decode

import psycopg2
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError as SA_OperationalError
from sqlalchemy.dialects.postgresql import BYTEA

import sys
# add to path our wrapper until not published to PYPI
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'wrappers/python'))

from acrawriter import create_acrastruct


metadata = sa.MetaData()
test_table = sa.Table('test', metadata,
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('data', sa.LargeBinary),
    sa.Column('raw_data', sa.String),
)

zones = []


def create_client_keypair(name, only_server=False, only_client=False):
    args = ['./acra_genkeys', '-client_id={}'.format(name)]
    if only_server:
        args.append('-acraserver')
    elif only_client:
        args.append('-acraproxy')
    return subprocess.call(args, cwd=os.getcwd())


def setUpModule():
    global zones
    # build binaries
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraproxy'], cwd=os.getcwd()) == 0
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_addzone'], cwd=os.getcwd()) == 0
    assert subprocess.call(
        ['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genkeys'], cwd=os.getcwd()) == 0
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraserver'], cwd=os.getcwd()) == 0
    # first keypair for using without zones
    assert create_client_keypair('keypair1') == 0
    assert create_client_keypair('keypair2') == 0
    # add two zones
    zones.append(json.loads(subprocess.check_output(
        ['./acra_addzone'], cwd=os.getcwd()).decode('utf-8')))
    zones.append(json.loads(subprocess.check_output(
        ['./acra_addzone'], cwd=os.getcwd()).decode('utf-8')))


def tearDownModule():
    import shutil
    shutil.rmtree('.acrakeys')
    for i in ['acraproxy', 'acraserver', 'acra_addzone', 'acra_genkeys']:
        try:
            os.remove(i)
        except:
            pass


class TestCompilation(unittest.TestCase):
    def testCompileAll(self):
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraproxy'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraserver'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_addzone'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genkeys'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genpoisonrecord'], cwd=os.getcwd()))


class BaseTestCase(unittest.TestCase):
    DB_HOST = os.environ.get('TEST_DB_HOST', '172.17.0.1')
    DB_USER = os.environ.get('TEST_DB_USER', 'postgres')
    DB_USER_PASSWORD = os.environ.get('TEST_DB_USER_PASSWORD', '<PASSWORD>')
    DB_NAME = os.environ.get('TEST_DB_NAME', 'postgres')
    DB_PORT = os.environ.get('TEST_DB_PORT', 5432)

    PROXY_PORT_1 = 9090
    PROXY_PORT_2 = 9091
    # for debugging with manually runned acra server
    EXTERNAL_ACRA = False
    ACRA_PORT = 10003
    if EXTERNAL_ACRA:
        ACRA_PORT = 9393

    ACRA_BYTEA = 'hex_bytea'
    DB_BYTEA = 'hex'
    ZONE = False<commit_msg>back default host to db from 172.17.0.1 to 127.0.0.1<commit_after># Copyright 2016, Cossack Labs Limited
#
# 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.
# coding: utf-8
import socket
import json
import time
import os
import random
import string
import subprocess
import unittest
from base64 import b64decode

import psycopg2
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError as SA_OperationalError
from sqlalchemy.dialects.postgresql import BYTEA

import sys
# add to path our wrapper until not published to PYPI
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'wrappers/python'))

from acrawriter import create_acrastruct


metadata = sa.MetaData()
test_table = sa.Table('test', metadata,
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('data', sa.LargeBinary),
    sa.Column('raw_data', sa.String),
)

zones = []


def create_client_keypair(name, only_server=False, only_client=False):
    args = ['./acra_genkeys', '-client_id={}'.format(name)]
    if only_server:
        args.append('-acraserver')
    elif only_client:
        args.append('-acraproxy')
    return subprocess.call(args, cwd=os.getcwd())


def setUpModule():
    global zones
    # build binaries
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraproxy'], cwd=os.getcwd()) == 0
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_addzone'], cwd=os.getcwd()) == 0
    assert subprocess.call(
        ['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genkeys'], cwd=os.getcwd()) == 0
    assert subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraserver'], cwd=os.getcwd()) == 0
    # first keypair for using without zones
    assert create_client_keypair('keypair1') == 0
    assert create_client_keypair('keypair2') == 0
    # add two zones
    zones.append(json.loads(subprocess.check_output(
        ['./acra_addzone'], cwd=os.getcwd()).decode('utf-8')))
    zones.append(json.loads(subprocess.check_output(
        ['./acra_addzone'], cwd=os.getcwd()).decode('utf-8')))


def tearDownModule():
    import shutil
    shutil.rmtree('.acrakeys')
    for i in ['acraproxy', 'acraserver', 'acra_addzone', 'acra_genkeys']:
        try:
            os.remove(i)
        except:
            pass


class TestCompilation(unittest.TestCase):
    def testCompileAll(self):
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraproxy'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acraserver'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_addzone'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genkeys'], cwd=os.getcwd()))
        self.assertFalse(subprocess.call(['go', 'build', 'github.com/cossacklabs/acra/cmd/acra_genpoisonrecord'], cwd=os.getcwd()))


class BaseTestCase(unittest.TestCase):
    DB_HOST = os.environ.get('TEST_DB_HOST', '127.0.0.1')
    DB_USER = os.environ.get('TEST_DB_USER', 'postgres')
    DB_USER_PASSWORD = os.environ.get('TEST_DB_USER_PASSWORD', '<PASSWORD>')
    DB_NAME = os.environ.get('TEST_DB_NAME', 'postgres')
    DB_PORT = os.environ.get('TEST_DB_PORT', 5432)

    PROXY_PORT_1 = 9090
    PROXY_PORT_2 = 9091
    # for debugging with manually runned acra server
    EXTERNAL_ACRA = False
    ACRA_PORT = 10003
    if EXTERNAL_ACRA:
        ACRA_PORT = 9393

    ACRA_BYTEA = 'hex_bytea'
    DB_BYTEA = 'hex'
    ZONE = False
{'fraction_non_alphanumeric': 0.1384125428711416, 'fraction_numerical': 0.014943655071043607, 'mean_word_length': 4.151419558359621, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, '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': '1917247', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2802, 'n_words': 615}