|
| 1 | +from django.db import migrations |
| 2 | +from django.utils.translation import gettext_lazy as _ |
| 3 | + |
| 4 | + |
| 5 | +def load_initial_data(app, *args, **kwargs): |
| 6 | + EligibilityType = app.get_model("core", "EligibilityType") |
| 7 | + |
| 8 | + type1 = EligibilityType.objects.create(name="type1", label="Eligibility Type 1", group_id="group1") |
| 9 | + type2 = EligibilityType.objects.create(name="type2", label="Eligibility Type 2", group_id="group2") |
| 10 | + |
| 11 | + PemData = app.get_model("core", "PemData") |
| 12 | + |
| 13 | + server_public_key = PemData.objects.create( |
| 14 | + text=""" |
| 15 | +-----BEGIN PUBLIC KEY----- |
| 16 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyYo6Pe9OSfPGX0oQXyLA |
| 17 | +blOwrMgc/j1JlF07b1ahq1lc3FH0XEk3Dzqbt9NuQs8hz6493vBNtNWTpVmvbGe4 |
| 18 | +VX3UjhpEARhN3m4jf/Z2OEuDt2A9q19NLSjgeyhieLkYLwN1ezYXrkn7cfOngcJM |
| 19 | +nGDXp45CaA+g3DzasrjETnKUdqecCzJ3FJ/RRwfibrju7eS/8s6H03nvydzeAJzT |
| 20 | +kEv7Fic2JJEUhh2rJhyLxt+qKkIYeBG+5fBri4miaS8FPnD/yjZzEAFsQc7n0dGq |
| 21 | +DAhSJS8tYNmXFmGlaCfRUBNV3mvOx0vFPuH21WQ5KKZxZP0e64/uQdotbPIImiyR |
| 22 | +JwIDAQAB |
| 23 | +-----END PUBLIC KEY----- |
| 24 | +
|
| 25 | +""", |
| 26 | + label="Eligibility server public key", |
| 27 | + ) |
| 28 | + |
| 29 | + client_private_key = PemData.objects.create( |
| 30 | + text=""" |
| 31 | +-----BEGIN RSA PRIVATE KEY----- |
| 32 | +MIIEpAIBAAKCAQEA1pt0ZoOuPEVPJJS+5r884zcjZLkZZ2GcPwr79XOLDbOi46on |
| 33 | +Ca79kjRnhS0VUK96SwUPS0z9J5mDA5LSNL2RoxFb5QGaevnJY828N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Iql0YjhE2ecGtLcU+Qm8 |
| 49 | +LTnwpg4GjmBnNTNGSCfB7IuYEsQK489R49Qw3xhwM5rkdRajmbCHm+Eiz+/+4NwY |
| 50 | +kt5I1/NMu7vYUR40MwyEuPSm3Q+bvEGu/71pL8wFIUVlshNJ5CN60fA8qqo+5kVK |
| 51 | +4Ntzy7Kq6WpC9Dhh75vE3ZcCgYEAty99uXtxsJD6+aEwcvcENkUwUztPQ6ggAwci |
| 52 | +je9Z/cmwCj6s9mN3HzfQ4qgGrZs4ycCK655xhilBFOIQJ3YRUKUaDYk4H0YDe |
| 53 | +Osf6gTP8wtQDH2GZSNlavLk5w7UFDYQD2b47y4fw+NaOEYvjPl0p5lmb6ebAPZb8 |
| 54 | +FbKZRd0CgYBC1HTbA+zMEqDdY4MWJJLC6jZsjdxOGhzjrCtWcIWEGMDF7oDDEoix |
| 55 | +W3j2hwm4C6vaNkH9XX1dr5+q6gq8vJQdbYoExl22BGMiNbfI3+sLRk0zBYL//W6c |
| 56 | +tSREgR4EjosqQfbkceLJ2JT1wuNjInI0eR9H3cRugvlDTeWtbdJ5qA== |
| 57 | +-----END RSA PRIVATE KEY----- |
| 58 | +""", |
| 59 | + label="Benefits client private key", |
| 60 | + ) |
| 61 | + |
| 62 | + dummy_cert = PemData.objects.create( |
| 63 | + text=""" |
| 64 | +-----BEGIN CERTIFICATE----- |
| 65 | +PEM DATA |
| 66 | +-----END CERTIFICATE----- |
| 67 | +""", |
| 68 | + label="Dummy certificate", |
| 69 | + ) |
| 70 | + |
| 71 | + AuthProvider = app.get_model("core", "AuthProvider") |
| 72 | + |
| 73 | + auth_provider = AuthProvider.objects.create( |
| 74 | + sign_in_button_label=_("eligibility.buttons.signin"), |
| 75 | + sign_out_button_label=_("eligibility.buttons.signout"), |
| 76 | + client_name="benefits-oauth-client-name", |
| 77 | + client_id="benefits-oauth-client-id", |
| 78 | + authority="https://example.com", |
| 79 | + scope="verify:type1", |
| 80 | + claim="type1", |
| 81 | + ) |
| 82 | + |
| 83 | + EligibilityVerifier = app.get_model("core", "EligibilityVerifier") |
| 84 | + |
| 85 | + verifier1 = EligibilityVerifier.objects.create( |
| 86 | + name="Test Eligibility Verifier 1", |
| 87 | + api_url="http://server:5000/verify", |
| 88 | + api_auth_header="X-Server-API-Key", |
| 89 | + api_auth_key="server-auth-token", |
| 90 | + eligibility_type=type1, |
| 91 | + public_key=server_public_key, |
| 92 | + jwe_cek_enc="A256CBC-HS512", |
| 93 | + jwe_encryption_alg="RSA-OAEP", |
| 94 | + jws_signing_alg="RS256", |
| 95 | + auth_provider=auth_provider, |
| 96 | + selection_label=_("eligibility.pages.index.dmv.label"), |
| 97 | + selection_label_description=None, |
| 98 | + start_content_title=_("eligibility.pages.start.dmv.content_title"), |
| 99 | + start_item_name=_("eligibility.pages.start.dmv.items[0].title"), |
| 100 | + start_item_description=_("eligibility.pages.start.dmv.items[0].text"), |
| 101 | + start_blurb=_("eligibility.pages.start.dmv.p[0]"), |
| 102 | + form_title=_("eligibility.pages.confirm.dmv.title"), |
| 103 | + form_content_title=_("eligibility.pages.confirm.dmv.content_title"), |
| 104 | + form_blurb=_("eligibility.pages.confirm.dmv.p[0]"), |
| 105 | + form_sub_label=_("eligibility.forms.confirm.dmv.fields.sub"), |
| 106 | + form_sub_placeholder="A1234567", |
| 107 | + form_sub_pattern=".+", |
| 108 | + form_name_label=_("eligibility.forms.confirm.dmv.fields.name"), |
| 109 | + form_name_placeholder="Rodriguez", |
| 110 | + form_name_max_length=255, |
| 111 | + unverified_title=_("eligibility.pages.unverified.dmv.title"), |
| 112 | + unverified_content_title=_("eligibility.pages.unverified.dmv.content_title"), |
| 113 | + unverified_blurb=_("eligibility.pages.unverified.dmv.p[0]"), |
| 114 | + ) |
| 115 | + |
| 116 | + verifier2 = EligibilityVerifier.objects.create( |
| 117 | + name="Test Eligibility Verifier 2", |
| 118 | + api_url="http://server:5000/verify", |
| 119 | + api_auth_header="X-Server-API-Key", |
| 120 | + api_auth_key="server-auth-token", |
| 121 | + eligibility_type=type2, |
| 122 | + public_key=server_public_key, |
| 123 | + jwe_cek_enc="A256CBC-HS512", |
| 124 | + jwe_encryption_alg="RSA-OAEP", |
| 125 | + jws_signing_alg="RS256", |
| 126 | + auth_provider=None, |
| 127 | + selection_label=_("eligibility.pages.index.mst.label"), |
| 128 | + selection_label_description=_("eligibility.pages.index.mst.description"), |
| 129 | + start_content_title=_("eligibility.pages.start.mst.content_title"), |
| 130 | + start_item_name=_("eligibility.pages.start.mst.items[0].title"), |
| 131 | + start_item_description=_("eligibility.pages.start.mst.items[0].text"), |
| 132 | + start_blurb=_("eligibility.pages.start.mst.p[0]"), |
| 133 | + form_title=_("eligibility.pages.confirm.mst.title"), |
| 134 | + form_content_title=_("eligibility.pages.confirm.mst.content_title"), |
| 135 | + form_blurb=_("eligibility.pages.confirm.mst.p[0]"), |
| 136 | + form_sub_label=_("eligibility.forms.confirm.mst.fields.sub"), |
| 137 | + form_sub_placeholder="B1234567", |
| 138 | + form_sub_pattern=".+", |
| 139 | + form_name_label=_("eligibility.forms.confirm.mst.fields.name"), |
| 140 | + form_name_placeholder="Garcia", |
| 141 | + form_name_max_length=255, |
| 142 | + unverified_title=_("eligibility.pages.unverified.mst.title"), |
| 143 | + unverified_content_title=_("eligibility.pages.unverified.mst.content_title"), |
| 144 | + unverified_blurb=_("eligibility.pages.unverified.mst.p[0]"), |
| 145 | + ) |
| 146 | + |
| 147 | + EligibilityVerifier.objects.create( |
| 148 | + name="OAuth claims via Login.gov", |
| 149 | + eligibility_type=type1, |
| 150 | + auth_provider=auth_provider, |
| 151 | + selection_label=_("eligibility.pages.index.oauth.label"), |
| 152 | + selection_label_description=None, |
| 153 | + start_content_title=_("eligibility.pages.start.oauth.content_title"), |
| 154 | + start_item_name=_("eligibility.pages.start.oauth.items[0].title"), |
| 155 | + start_item_description=_("eligibility.pages.start.oauth.items[0].text"), |
| 156 | + start_blurb=_("eligibility.pages.start.oauth.p[0]"), |
| 157 | + unverified_title=_("eligibility.pages.unverified.oauth.title"), |
| 158 | + unverified_content_title=_("eligibility.pages.unverified.oauth.content_title"), |
| 159 | + unverified_blurb=_("eligibility.pages.unverified.oauth.p[0]"), |
| 160 | + ) |
| 161 | + |
| 162 | + PaymentProcessor = app.get_model("core", "PaymentProcessor") |
| 163 | + |
| 164 | + payment_processor = PaymentProcessor.objects.create( |
| 165 | + name="Test Payment Processor", |
| 166 | + api_base_url="http://server:5000", |
| 167 | + api_access_token_endpoint="access-token", |
| 168 | + api_access_token_request_key="request_access", |
| 169 | + api_access_token_request_val="REQUEST_ACCESS", |
| 170 | + card_tokenize_url="http://localhost:5000/static/tokenize.js", |
| 171 | + card_tokenize_func="tokenize", |
| 172 | + card_tokenize_env="test", |
| 173 | + client_cert=dummy_cert, |
| 174 | + client_cert_private_key=client_private_key, |
| 175 | + client_cert_root_ca=dummy_cert, |
| 176 | + customer_endpoint="customer", |
| 177 | + customers_endpoint="customers", |
| 178 | + group_endpoint="group", |
| 179 | + ) |
| 180 | + |
| 181 | + TransitAgency = app.get_model("core", "TransitAgency") |
| 182 | + |
| 183 | + transit_agency1 = TransitAgency.objects.create( |
| 184 | + slug="abc", |
| 185 | + short_name="ABC", |
| 186 | + long_name="ABC Transit Company", |
| 187 | + agency_id="abc123", |
| 188 | + merchant_id="abc", |
| 189 | + info_url="https://www.example.com/help", |
| 190 | + phone="800-555-5555", |
| 191 | + active=True, |
| 192 | + private_key=client_private_key, |
| 193 | + jws_signing_alg="RS256", |
| 194 | + payment_processor=payment_processor, |
| 195 | + ) |
| 196 | + transit_agency1.eligibility_types.set([type1, type2]) |
| 197 | + transit_agency1.eligibility_verifiers.set([verifier1, verifier2]) |
| 198 | + |
| 199 | + transit_agency2 = TransitAgency.objects.create( |
| 200 | + slug="deftl", |
| 201 | + short_name="DefTL", |
| 202 | + long_name="DEF Transit Lines", |
| 203 | + agency_id="def456", |
| 204 | + merchant_id="deftl", |
| 205 | + info_url="https://www.example.com/help", |
| 206 | + phone="321-555-5555", |
| 207 | + active=True, |
| 208 | + private_key=client_private_key, |
| 209 | + jws_signing_alg="RS256", |
| 210 | + payment_processor=payment_processor, |
| 211 | + ) |
| 212 | + transit_agency2.eligibility_types.set([type1]) |
| 213 | + transit_agency2.eligibility_verifiers.set([verifier1]) |
| 214 | + |
| 215 | + |
| 216 | +class Migration(migrations.Migration): |
| 217 | + |
| 218 | + dependencies = [ |
| 219 | + ("core", "0001_initial"), |
| 220 | + ] |
| 221 | + |
| 222 | + operations = [ |
| 223 | + migrations.RunPython(load_initial_data), |
| 224 | + ] |
0 commit comments