1
0
mirror of https://github.com/google/nomulus synced 2026-06-09 16:33:02 +00:00

Compare commits

...

29 Commits

Author SHA1 Message Date
Weimin Yu da28a2021c Use Gmail in Icann reporting actions (#2119) 2023-08-23 14:39:26 -04:00
Weimin Yu ffd952a60e Fix Cloud Tasks retry failure (#2118)
* Fix Cloud Tasks failure to retry

Replace `SC_NOT_MODIFIED` (304) with `SC_SERVICE_UNAVAILABLE` (503) when
data is not available yet. Affected actions are invoice- and spec11-publishing.

It is confirmed that Cloud Tasks currently does not retry with code 304,
despite the public documentation stating so. We will use 503 for now,
pending the decision by Cloud Tasks whether to change behavior or
documentation.

The code `TOO_EARLY` (425) is another alternative. It is not meant for
our use case but at least sounds like it is. However, it is not in any
javax.servlet jar. We don't want to define our own constant, and we cannot upgrade
to jakarta.servlet yet.

Also revert previous mitigation.
2023-08-23 10:55:51 -04:00
gbrodman 97676d1a1f Add backend for editing whois-visible fields (#2100)
This includes a bit of refactoring of the GSON creation. There can exist
some objects (e.g. Address) where the JSON representation is not equal to the
representation that we store in the database. For these objects, when
deserializing, we should update the objects so that they reflect the
proper DB structure (indeed, this is already what we do for the XML
parsing of Address).
2023-08-22 16:40:02 -04:00
sarahcaseybot 1dcbc9e0cb Change PackagePromotion to BulkPricingPackage (#2096)
* Change PackagePromotion to BulkPricingPackage

* More name changes

* Fix some test names

* Change token type "BULK" to "BULK_PRICING"

* Fix missed token_type reference

* Add todo to remove package type
2023-08-22 16:39:24 -04:00
Lai Jiang f59c387b9c Add the ability to specify per-transaction isolation level (#2104)
A config file field is added to control if per-transaction isolation
level is actually used. If set to true, nested transactions will throw
a runtime exception as the enclosing transaction may run at a different
isolation level.

In this PR we only add the ability to specify the isolation level,
without enabling it in any environment (including unit tests), or
actually specifying one for any query. This should allow us to set up
the system without impacting anything currently working.
2023-08-21 18:48:34 -04:00
Weimin Yu cfcafeefc6 Mitigate Cloud task retry problem (#2116)
* Mitigate Cloud task retry problem

Increase PublishSpec11Action start delay to avoid the need to retry.

The only other use case is invoice, which typically does not retry:
delay is 10 minutes, pipeline finishes within 7 minutes.
2023-08-18 17:14:03 -04:00
Weimin Yu c32d831dd6 Add logging about Spec11 email sending (#2115) 2023-08-18 15:02:03 -04:00
Ben McIlwain b38e0efe9a Refactor the way that the console BE parses POST bodies (#2113) (#2109)
This includes two changes:
1. Creating a base string-type adapter for use parsing to/from JSON
   classes that are represented as simple strings
2. Changing the object-provider methods so that the POST bodies should
   contain precisely the expected object(s) and nothing else. This way,
   it's easier for the frontend and backend to agree that, for instance,
   one POST endpoint might accept exactly a Registrar object, or a list
   of Contact objects.

Co-Authored-By: gbrodman <gbrodman@google.com>
2023-08-18 12:30:35 -04:00
Lai Jiang 67cb411c99 Remove DatabaseSnapshot (#2105)
It is no longer being used.
2023-08-17 22:40:54 -04:00
gbrodman 9f551eb552 Refactor the way that the console BE parses POST bodies (#2113)
This includes two changes:
1. Creating a base string-type adapter for use parsing to/from JSON
   classes that are represented as simple strings
2. Changing the object-provider methods so that the POST bodies should
   contain precisely the expected object(s) and nothing else. This way,
   it's easier for the frontend and backend to agree that, for instance,
   one POST endpoint might accept exactly a Registrar object, or a list
   of Contact objects.
2023-08-17 15:51:21 -04:00
sarahcaseybot 655f05c58c Remove references to cloud-build-local (#2111)
* Update cloudbuild-nomulus to save standardTest logs to GCS

* Remove step changes from cloudbuild-nomulus
2023-08-17 15:26:41 -04:00
Pavlo Tkach 95c810ddf4 Add script to allow quickly update number of instances (#2112)
This is a fast and easy way to update number of instances for the service deployed to app engine. Works with manual-scaling types services.
2023-08-17 12:33:35 -04:00
Pavlo Tkach ec9a220bc3 Add console registrars screen API support to /console-api/registrars endpoint (#2095) 2023-08-17 10:17:23 -04:00
Weimin Yu 68d35d2d95 Fix unicode issue in GetTldCommand (#2108) 2023-08-16 12:24:35 -04:00
Weimin Yu 99840488a1 Fix TldTest (#2107)
Test data should be loaded from resources, not source tree.
2023-08-16 11:31:21 -04:00
Lai Jiang ee7c8fb018 Disable flaky tests temporarily (#2106) 2023-08-15 13:59:56 -04:00
Weimin Yu c6f62dcffd Fix the alert recipient address for Spec11 (#2103)
During email migration, alerts should be sent to the address
annotated with `newAlertRecipientEmailAddress`.
2023-08-10 15:38:13 -04:00
sarahcaseybot ee66805d2e Modify getTldCommand to return TLD in YAML (#2102) 2023-08-10 14:20:56 -04:00
Weimin Yu d7a3c0c439 Send Spec11 emails using Gmail (#2101)
First of a series of migrations to Gmail.

This can only be verified in production.
2023-08-10 10:26:28 -04:00
Weimin Yu 45666773ee Enable/disable email sending by environments (#2099) 2023-08-09 10:46:48 -04:00
Lai Jiang b8b5152336 Bump PUBAPI instance number to 24 (#2098) 2023-08-08 11:23:50 -04:00
Weimin Yu 0f6302e92b Add tests to GmailClient (#2097)
Also make GmailClient do retries on transit errors.
2023-08-07 16:05:15 -04:00
Lai Jiang e594bd13a1 Revert google-cloud-storage to 2.22.6 (#2093)
2.25.0 contains a breaking change that made HttpStorageOptions not
serializeable, which breaks RDE as it needs to access GCS from Beam.

2.22.6 was the last version that was used before the Gradle upgrade.

Also had to downgrade google-cloud-nio to pass the tests.

For some inexplicable reason, I had to manually add
guava-listenablefuture as
testRuntimeClasspath/runtimeClasspath/deploy_jar dependencies to the
networking, docs and prober subprojects' lock files, as running
`gradle test --write-locks` would NOT add them and succeed; but without
`--write-locks`, running the corresponding tests would fail.

See: b/294378137.
2023-08-07 12:21:08 -04:00
gbrodman 00051dbc0f Ignore/exclude IDEA-generated classpath index files (#2094)
See
https://youtrack.jetbrains.com/issue/IDEA-305759/Gradle-cannot-handle-classpath.index-duplicates
for more info -- it looks like this is fixed in some recent versions but
as of right now it doesn't seem like it's fixed on the Google-managed
version
2023-08-07 11:10:25 -04:00
Weimin Yu aab89fb816 Re-enable flyway deadlock check (#2092)
Use a system property to specify whether this check should be executed.

We will update the presubmit test script to run this check only during
foss-pr.
2023-08-03 15:34:30 -04:00
sarahcaseybot 6ea548a35d Change static __REMOVEPACKAGE__ token to __REMOVEDOMAIN__ token (#2090)
* Change static __REMOVEPACKAGE__ token to __REMOVEDOMAIN__ token

* FIx some references

* Fix variable name

* Update docs
2023-08-03 14:09:43 -04:00
sarahcaseybot 733e9a4a6a Change packageToken extension to bulkToken extension (#2091)
* Change packageToken extension to bulkToken extension

* Small fixes
2023-08-02 17:06:20 -04:00
Weimin Yu 10d28efa1c Add placeholder configs for Gmail (#2089)
Add placeholder configs for sending emails using Gmail in GSuite.

The names of the new configs are temporary. After migration they
will revert to the names currently in use by the AppEngine email API.
2023-08-02 16:09:45 -04:00
Weimin Yu 1e0a0cf29e Temporarily disable flyway single-table check (#2088) 2023-07-31 14:34:53 -04:00
152 changed files with 3170 additions and 2007 deletions
+1
View File
@@ -79,6 +79,7 @@ autogenerated/
**/*.iml
nomulus.ipr
nomulus.iws
**/classpath.index
# Auto-generated java classes by Intellij
*/src/main/generated/
+32 -32
View File
@@ -3,31 +3,31 @@
# This file is expected to be part of source control.
aopalliance:aopalliance:1.0=buildScriptClasspath,compileClasspath
args4j:args4j:2.0.23=buildScriptClasspath,compileClasspath
com.fasterxml.jackson.core:jackson-core:2.15.2=buildScriptClasspath,compileClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=buildScriptClasspath,compileClasspath
com.fasterxml.jackson.core:jackson-core:2.14.2=buildScriptClasspath,compileClasspath
com.fasterxml.jackson:jackson-bom:2.14.2=buildScriptClasspath,compileClasspath
com.github.ben-manes.caffeine:caffeine:2.7.0=annotationProcessor
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor
com.google.android:annotations:4.1.1.4=buildScriptClasspath
com.google.api-client:google-api-client:2.2.0=buildScriptClasspath,compileClasspath
com.google.api.grpc:gapic-google-cloud-storage-v2:2.25.0-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:grpc-google-cloud-storage-v2:2.25.0-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-cloud-storage-v2:2.25.0-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-common-protos:2.22.1=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-iam-v1:1.17.1=buildScriptClasspath,compileClasspath
com.google.api:api-common:2.14.1=buildScriptClasspath,compileClasspath
com.google.api:gax-grpc:2.31.1=buildScriptClasspath,compileClasspath
com.google.api:gax-httpjson:2.31.1=buildScriptClasspath,compileClasspath
com.google.api:gax:2.31.1=buildScriptClasspath,compileClasspath
com.google.apis:google-api-services-storage:v1-rev20230617-2.0.0=buildScriptClasspath,compileClasspath
com.google.api.grpc:gapic-google-cloud-storage-v2:2.22.6-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:grpc-google-cloud-storage-v2:2.22.6-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-cloud-storage-v2:2.22.6-alpha=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-common-protos:2.22.0=buildScriptClasspath,compileClasspath
com.google.api.grpc:proto-google-iam-v1:1.17.0=buildScriptClasspath,compileClasspath
com.google.api:api-common:2.14.0=buildScriptClasspath,compileClasspath
com.google.api:gax-grpc:2.31.0=buildScriptClasspath,compileClasspath
com.google.api:gax-httpjson:2.31.0=buildScriptClasspath,compileClasspath
com.google.api:gax:2.31.0=buildScriptClasspath,compileClasspath
com.google.apis:google-api-services-storage:v1-rev20230301-2.0.0=buildScriptClasspath,compileClasspath
com.google.auth:google-auth-library-credentials:1.19.0=buildScriptClasspath,compileClasspath
com.google.auth:google-auth-library-oauth2-http:1.19.0=buildScriptClasspath,compileClasspath
com.google.auto.value:auto-value-annotations:1.10.2=buildScriptClasspath,compileClasspath
com.google.auto.value:auto-value-annotations:1.10.1=buildScriptClasspath,compileClasspath
com.google.auto.value:auto-value:1.10.2=annotationProcessor
com.google.auto:auto-common:0.10=annotationProcessor
com.google.cloud:google-cloud-core-grpc:2.21.1=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-core-http:2.21.1=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-core:2.21.1=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-storage:2.25.0=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-core-grpc:2.21.0=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-core-http:2.21.0=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-core:2.21.0=buildScriptClasspath,compileClasspath
com.google.cloud:google-cloud-storage:2.22.6=buildScriptClasspath,compileClasspath
com.google.code.findbugs:jFormatString:3.0.0=annotationProcessor
com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,buildScriptClasspath,compileClasspath
com.google.code.gson:gson:2.10.1=buildScriptClasspath,compileClasspath
@@ -58,26 +58,26 @@ com.google.oauth-client:google-oauth-client:1.34.1=buildScriptClasspath,compileC
com.google.protobuf:protobuf-java-util:3.23.2=buildScriptClasspath,compileClasspath
com.google.protobuf:protobuf-java:3.23.2=buildScriptClasspath,compileClasspath
com.google.protobuf:protobuf-java:3.4.0=annotationProcessor
com.google.re2j:re2j:1.7=buildScriptClasspath
com.google.re2j:re2j:1.6=buildScriptClasspath
com.google.template:soy:2021-02-01=buildScriptClasspath,compileClasspath
com.googlecode.java-diff-utils:diffutils:1.3.0=annotationProcessor
com.ibm.icu:icu4j:57.1=buildScriptClasspath,compileClasspath
commons-codec:commons-codec:1.15=buildScriptClasspath,compileClasspath
commons-logging:commons-logging:1.2=buildScriptClasspath,compileClasspath
io.grpc:grpc-alts:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-api:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-auth:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-context:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-core:1.56.1=buildScriptClasspath
io.grpc:grpc-googleapis:1.56.1=buildScriptClasspath
io.grpc:grpc-grpclb:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-netty-shaded:1.56.1=buildScriptClasspath
io.grpc:grpc-protobuf-lite:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-protobuf:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-rls:1.56.1=buildScriptClasspath
io.grpc:grpc-services:1.56.1=buildScriptClasspath
io.grpc:grpc-stub:1.56.1=buildScriptClasspath,compileClasspath
io.grpc:grpc-xds:1.56.1=buildScriptClasspath
io.grpc:grpc-alts:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-api:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-auth:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-context:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-core:1.55.3=buildScriptClasspath
io.grpc:grpc-googleapis:1.55.3=buildScriptClasspath
io.grpc:grpc-grpclb:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-netty-shaded:1.55.3=buildScriptClasspath
io.grpc:grpc-protobuf-lite:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-protobuf:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-rls:1.55.3=buildScriptClasspath
io.grpc:grpc-services:1.55.3=buildScriptClasspath
io.grpc:grpc-stub:1.55.3=buildScriptClasspath,compileClasspath
io.grpc:grpc-xds:1.55.3=buildScriptClasspath
io.opencensus:opencensus-api:0.31.1=buildScriptClasspath,compileClasspath
io.opencensus:opencensus-contrib-http-util:0.31.1=buildScriptClasspath,compileClasspath
io.opencensus:opencensus-proto:0.2.0=buildScriptClasspath
+8 -9
View File
@@ -4,12 +4,12 @@
com.github.ben-manes.caffeine:caffeine:2.7.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.github.ben-manes.caffeine:caffeine:2.9.3=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.auto.value:auto-value-annotations:1.8.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.auto.value:auto-value-annotations:1.10.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.auto:auto-common:0.10=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.code.findbugs:jFormatString:3.0.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,checkstyle,compileClasspath,deploy_jar,errorprone,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath,testing,testingAnnotationProcessor,testingCompileClasspath
com.google.errorprone:error_prone_annotation:2.3.4=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.errorprone:error_prone_annotations:2.18.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.errorprone:error_prone_annotations:2.19.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.errorprone:error_prone_annotations:2.3.4=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.errorprone:error_prone_annotations:2.7.1=checkstyle
com.google.errorprone:error_prone_check_api:2.3.4=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
@@ -17,16 +17,16 @@ com.google.errorprone:error_prone_core:2.3.4=annotationProcessor,errorprone,test
com.google.errorprone:error_prone_type_annotations:2.3.4=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.flogger:flogger:0.7.4=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.guava:failureaccess:1.0.1=annotationProcessor,checkstyle,compileClasspath,deploy_jar,errorprone,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath,testing,testingAnnotationProcessor,testingCompileClasspath
com.google.guava:guava-parent:32.1.1-jre=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.guava:guava-parent:32.1.2-jre=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.guava:guava:27.0.1-jre=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.guava:guava:31.0.1-jre=checkstyle
com.google.guava:guava:32.1.1-jre=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,checkstyle,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.guava:guava:32.1.2-jre=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,checkstyle,compileClasspath,deploy_jar,errorprone,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath,testing,testingAnnotationProcessor,testingCompileClasspath
com.google.j2objc:j2objc-annotations:1.1=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.j2objc:j2objc-annotations:1.3=checkstyle
com.google.j2objc:j2objc-annotations:2.8=compileClasspath,testCompileClasspath,testingCompileClasspath
com.google.protobuf:protobuf-java:3.4.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.google.truth:truth:1.1.3=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.google.truth:truth:1.1.5=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
com.googlecode.java-diff-utils:diffutils:1.3.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
com.puppycrawl.tools:checkstyle:9.3=checkstyle
commons-beanutils:commons-beanutils:1.9.4=checkstyle
@@ -42,7 +42,7 @@ org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
org.checkerframework:checker-compat-qual:2.5.3=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.checkerframework:checker-qual:3.0.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
org.checkerframework:checker-qual:3.12.0=checkstyle
org.checkerframework:checker-qual:3.33.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.checkerframework:checker-qual:3.35.0=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.checkerframework:dataflow:3.0.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
org.checkerframework:javacutil:3.0.0=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
org.codehaus.mojo:animal-sniffer-annotations:1.17=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
@@ -60,8 +60,7 @@ org.junit:junit-bom:5.10.0=testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-commons:9.5=jacocoAnt
org.ow2.asm:asm-tree:9.5=jacocoAnt
org.ow2.asm:asm:9.1=compileClasspath,deploy_jar,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.ow2.asm:asm:9.5=jacocoAnt
org.ow2.asm:asm:9.5=compileClasspath,deploy_jar,jacocoAnt,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,testing,testingCompileClasspath
org.pcollections:pcollections:2.1.2=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
org.plumelib:plume-util:1.0.6=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
org.plumelib:reflection-util:0.0.2=annotationProcessor,errorprone,testAnnotationProcessor,testingAnnotationProcessor
-7
View File
@@ -109,13 +109,6 @@ PRESUBMITS = {
"System.(out|err).println is only allowed in tools/ packages. Please "
"use a logger instead.",
# PostgreSQLContainer instantiation must specify docker tag
# TODO(b/204572437): Fix the pattern to pass DatabaseSnapshotTest.java
PresubmitCheck(
r"[\s\S]*new\s+PostgreSQLContainer(<[\s\S]*>)?\(\s*\)[\s\S]*",
"java", {"DatabaseSnapshotTest.java"}):
"PostgreSQLContainer instantiation must specify docker tag.",
# Various Soy linting checks
PresubmitCheck(
r".* (/\*)?\* {?@param ",
@@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, catchError, of } from 'rxjs';
import { Contact } from '../../settings/contact/contact.service';
import { Injectable } from '@angular/core';
import { catchError, Observable, of } from 'rxjs';
import { SecuritySettingsBackendModel } from 'src/app/settings/security/security.service';
import { Contact } from '../../settings/contact/contact.service';
@Injectable()
export class BackendService {
constructor(private http: HttpClient) {}
@@ -55,7 +56,7 @@ export class BackendService {
): Observable<Contact[]> {
return this.http.post<Contact[]>(
`/console-api/settings/contacts?registrarId=${registrarId}`,
{ contacts }
contacts
);
}
@@ -85,7 +86,7 @@ export class BackendService {
): Observable<SecuritySettingsBackendModel> {
return this.http.post<SecuritySettingsBackendModel>(
`/console-api/settings/security?registrarId=${registrarId}`,
{ registrar: securitySettings }
securitySettings
);
}
}
+30 -44
View File
@@ -8,22 +8,14 @@ args4j:args4j:2.0.26=css
cglib:cglib-nodep:2.2=css
com.101tec:zkclient:0.10=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.beust:jcommander:1.60=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-joda:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-joda:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.14.2=testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-joda:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.14.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml:classmate:1.5.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.github.ben-manes.caffeine:caffeine:2.7.0=annotationProcessor,errorprone,nonprodAnnotationProcessor,testAnnotationProcessor
com.github.ben-manes.caffeine:caffeine:2.9.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -45,8 +37,7 @@ com.google.api-client:google-api-client-jackson2:1.32.2=compileClasspath,deploy_
com.google.api-client:google-api-client-java6:1.35.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api-client:google-api-client-servlet:1.35.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api-client:google-api-client:1.35.2=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:gapic-google-cloud-storage-v2:2.22.6-alpha=testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:gapic-google-cloud-storage-v2:2.25.0-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.api.grpc:gapic-google-cloud-storage-v2:2.22.6-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-bigquerystorage-v1:2.38.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-bigquerystorage-v1beta1:0.162.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-bigquerystorage-v1beta2:0.162.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -56,8 +47,7 @@ com.google.api.grpc:grpc-google-cloud-pubsublite-v1:1.12.8=compileClasspath,depl
com.google.api.grpc:grpc-google-cloud-spanner-admin-database-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-spanner-admin-instance-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-spanner-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-storage-v2:2.22.6-alpha=testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-cloud-storage-v2:2.25.0-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.api.grpc:grpc-google-cloud-storage-v2:2.22.6-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:grpc-google-common-protos:2.20.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-bigquerystorage-v1:2.38.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-bigquerystorage-v1beta1:0.162.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -75,8 +65,7 @@ com.google.api.grpc:proto-google-cloud-secretmanager-v1beta1:2.22.0=compileClass
com.google.api.grpc:proto-google-cloud-spanner-admin-database-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-spanner-admin-instance-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-spanner-v1:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-storage-v2:2.22.6-alpha=testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-storage-v2:2.25.0-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.api.grpc:proto-google-cloud-storage-v2:2.22.6-alpha=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-tasks-v2:2.22.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-tasks-v2beta2:0.112.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api.grpc:proto-google-cloud-tasks-v2beta3:0.112.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -101,7 +90,8 @@ com.google.apis:google-api-services-monitoring:v3-rev20230529-2.0.0=compileClass
com.google.apis:google-api-services-pubsub:v1-rev20220904-2.0.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-sheets:v4-rev20230526-2.0.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-sqladmin:v1beta4-rev20230607-2.0.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-storage:v1-rev20230617-2.0.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-storage:v1-rev20230301-2.0.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.apis:google-api-services-storage:v1-rev20230617-2.0.0=testCompileClasspath,testRuntimeClasspath
com.google.appengine:appengine-api-1.0-sdk:1.9.86=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.appengine:appengine-api-1.0-sdk:2.0.16=testCompileClasspath,testRuntimeClasspath
com.google.appengine:appengine-api-stubs:2.0.16=testCompileClasspath,testRuntimeClasspath
@@ -125,12 +115,9 @@ com.google.cloud.sql:postgres-socket-factory:1.13.1=deploy_jar,runtimeClasspath,
com.google.cloud:google-cloud-bigquerystorage:2.38.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-bigtable-stats:2.23.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-bigtable:2.23.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core-grpc:2.21.0=testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core-grpc:2.21.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.cloud:google-cloud-core-http:2.21.0=testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core-http:2.21.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.cloud:google-cloud-core:2.21.0=testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core:2.21.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.cloud:google-cloud-core-grpc:2.21.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core-http:2.21.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-core:2.21.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-firestore:3.13.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-monitoring:1.82.0=compileClasspath,nonprodCompileClasspath,testCompileClasspath
com.google.cloud:google-cloud-monitoring:3.20.0=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
@@ -139,8 +126,7 @@ com.google.cloud:google-cloud-pubsub:1.123.14=compileClasspath,deploy_jar,nonpro
com.google.cloud:google-cloud-pubsublite:1.12.8=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-secretmanager:2.22.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-spanner:6.43.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-storage:2.22.6=testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-storage:2.25.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.cloud:google-cloud-storage:2.22.6=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-tasks:2.22.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:grpc-gcp:1.4.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.cloud:proto-google-cloud-firestore-bundle-v1:3.13.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -171,13 +157,15 @@ com.google.flogger:flogger:0.7.4=compileClasspath,deploy_jar,nonprodCompileClass
com.google.flogger:google-extensions:0.7.4=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.googlejavaformat:google-java-format:1.5=annotationProcessor,testAnnotationProcessor
com.google.guava:failureaccess:1.0.1=annotationProcessor,checkstyle,compileClasspath,deploy_jar,errorprone,nonprodAnnotationProcessor,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,soy,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.guava:guava-parent:32.1.1-jre=annotationProcessor,compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.guava:guava-testlib:32.1.1-jre=testCompileClasspath,testRuntimeClasspath
com.google.guava:guava-parent:32.1.1-jre=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.guava:guava-parent:32.1.2-jre=annotationProcessor,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.guava:guava-testlib:32.1.2-jre=testCompileClasspath,testRuntimeClasspath
com.google.guava:guava:20.0=css
com.google.guava:guava:27.0.1-jre=errorprone,nonprodAnnotationProcessor
com.google.guava:guava:31.0.1-jre=checkstyle,soy
com.google.guava:guava:32.1.1-jre=annotationProcessor,compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=checkstyle,errorprone,nonprodAnnotationProcessor,soy
com.google.guava:guava:32.1.1-jre=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
com.google.guava:guava:32.1.2-jre=annotationProcessor,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,checkstyle,errorprone,nonprodAnnotationProcessor,soy,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
com.google.gwt:gwt-user:2.10.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.http-client:google-http-client-apache-v2:1.43.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.http-client:google-http-client-appengine:1.43.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -212,7 +200,7 @@ com.google.protobuf:protobuf-java:4.0.0-rc-2=soy
com.google.re2j:re2j:1.6=compileClasspath,nonprodCompileClasspath,testCompileClasspath
com.google.re2j:re2j:1.7=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.template:soy:2021-02-01=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,soy,testCompileClasspath,testRuntimeClasspath
com.google.truth.extensions:truth-java8-extension:1.1.3=testCompileClasspath,testRuntimeClasspath
com.google.truth.extensions:truth-java8-extension:1.1.5=testCompileClasspath,testRuntimeClasspath
com.google.truth:truth:1.1.3=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath
com.google.truth:truth:1.1.5=testCompileClasspath,testRuntimeClasspath
com.googlecode.java-diff-utils:diffutils:1.3.0=annotationProcessor,errorprone,nonprodAnnotationProcessor,testAnnotationProcessor
@@ -269,8 +257,7 @@ io.grpc:grpc-netty-shaded:1.56.1=compileClasspath,deploy_jar,nonprodCompileClass
io.grpc:grpc-netty:1.55.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.grpc:grpc-protobuf-lite:1.56.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.grpc:grpc-protobuf:1.56.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.grpc:grpc-rls:1.55.3=testRuntimeClasspath
io.grpc:grpc-rls:1.56.1=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath
io.grpc:grpc-rls:1.55.3=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
io.grpc:grpc-services:1.55.1=compileClasspath,nonprodCompileClasspath,testCompileClasspath
io.grpc:grpc-services:1.56.1=deploy_jar,nonprodRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
io.grpc:grpc-stub:1.56.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -319,8 +306,7 @@ javax.validation:validation-api:1.0.0.GA=compileClasspath,deploy_jar,nonprodComp
javax.xml.bind:jaxb-api:2.3.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
javax.xml.bind:jaxb-api:2.4.0-b180830.0359=jaxb
jline:jline:1.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
joda-time:joda-time:2.10.10=testCompileClasspath,testRuntimeClasspath
joda-time:joda-time:2.10.14=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
joda-time:joda-time:2.10.10=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
junit:junit:4.13.2=nonprodCompileClasspath,nonprodRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
net.arnx:nashorn-promise:0.1.1=nonprodRuntime,runtime,testRuntimeClasspath
net.bytebuddy:byte-buddy-agent:1.14.5=testCompileClasspath,testRuntimeClasspath
@@ -358,7 +344,8 @@ org.apache.beam:beam-vendor-guava-26_0-jre:0.1=compileClasspath,deploy_jar,nonpr
org.apache.commons:commons-compress:1.23.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.apache.commons:commons-csv:1.10.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.apache.commons:commons-exec:1.3=nonprodRuntime,runtime,testCompileClasspath,testRuntimeClasspath
org.apache.commons:commons-lang3:3.12.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.apache.commons:commons-lang3:3.12.0=testCompileClasspath,testRuntimeClasspath
org.apache.commons:commons-lang3:3.13.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
org.apache.commons:commons-text:1.10.0=testCompileClasspath,testRuntimeClasspath
org.apache.ftpserver:ftplet-api:1.2.0=testCompileClasspath,testRuntimeClasspath
org.apache.ftpserver:ftpserver-core:1.2.0=testCompileClasspath,testRuntimeClasspath
@@ -396,7 +383,7 @@ org.eclipse.jetty:jetty-server:9.4.49.v20220914=compileClasspath,deploy_jar,nonp
org.eclipse.jetty:jetty-servlet:9.4.49.v20220914=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-util-ajax:9.4.49.v20220914=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-util:9.4.49.v20220914=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.flywaydb:flyway-core:9.21.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.flywaydb:flyway-core:9.21.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.glassfish.jaxb:jaxb-core:4.0.3=nonprodRuntime,runtime
org.glassfish.jaxb:jaxb-runtime:2.3.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.glassfish.jaxb:jaxb-runtime:4.0.3=nonprodRuntime,runtime
@@ -500,8 +487,7 @@ org.tukaani:xz:1.5=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRu
org.w3c.css:sac:1.3=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.webjars.npm:viz.js-graphviz-java:2.1.3=nonprodRuntime,runtime,testRuntimeClasspath
org.xerial.snappy:snappy-java:1.1.10.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.yaml:snakeyaml:1.33=testCompileClasspath,testRuntimeClasspath
org.yaml:snakeyaml:2.0=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath
org.yaml:snakeyaml:1.33=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
us.fatehi:schemacrawler-api:16.10.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
us.fatehi:schemacrawler-diagram:16.10.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
us.fatehi:schemacrawler-tools:16.10.1=compileClasspath,deploy_jar,nonprodCompileClasspath,nonprodRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -71,7 +71,7 @@ public class CannedScriptExecutionAction implements Runnable {
GmailClient gmailClient,
@Config("projectId") String projectId,
@Config("gSuiteDomainName") String gSuiteDomainName,
@Config("alertRecipientEmailAddress") InternetAddress recipientAddress) {
@Config("newAlertRecipientEmailAddress") InternetAddress recipientAddress) {
this.groupsConnection = groupsConnection;
this.gmailClient = gmailClient;
this.gSuiteDomainName = gSuiteDomainName;
@@ -116,6 +116,8 @@ public class CannedScriptExecutionAction implements Runnable {
try {
Set<String> currentMembers = groupsConnection.getMembersOfGroup(groupKey);
logger.atInfo().log("%s has %s members.", groupKey, currentMembers.size());
// One success is enough for validation.
return;
} catch (IOException e) {
logger.atWarning().withCause(e).log("Failed to check %s", groupKey);
}
@@ -0,0 +1,246 @@
// Copyright 2022 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.batch;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.primitives.Ints;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.Action.Service;
import google.registry.request.auth.Auth;
import google.registry.ui.server.SendEmailUtils;
import google.registry.util.Clock;
import java.util.Optional;
import javax.inject.Inject;
import org.joda.time.Days;
/**
* An action that checks all {@link BulkPricingPackage} objects for compliance with their max create
* limit.
*/
@Action(
service = Service.BACKEND,
path = CheckBulkComplianceAction.PATH,
auth = Auth.AUTH_API_ADMIN)
public class CheckBulkComplianceAction implements Runnable {
public static final String PATH = "/_dr/task/checkBulkCompliance";
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SendEmailUtils sendEmailUtils;
private final Clock clock;
private final String bulkPricingPackageCreateLimitEmailSubject;
private final String bulkPricingPackageDomainLimitWarningEmailSubject;
private final String bulkPricingPackageDomainLimitUpgradeEmailSubject;
private final String bulkPricingPackageCreateLimitEmailBody;
private final String bulkPricingPackageDomainLimitWarningEmailBody;
private final String bulkPricingPackageDomainLimitUpgradeEmailBody;
private final String registrySupportEmail;
private static final int THIRTY_DAYS = 30;
private static final int FORTY_DAYS = 40;
@Inject
public CheckBulkComplianceAction(
SendEmailUtils sendEmailUtils,
Clock clock,
@Config("bulkPricingPackageCreateLimitEmailSubject")
String bulkPricingPackageCreateLimitEmailSubject,
@Config("bulkPricingPackageDomainLimitWarningEmailSubject")
String bulkPricingPackageDomainLimitWarningEmailSubject,
@Config("bulkPricingPackageDomainLimitUpgradeEmailSubject")
String bulkPricingPackageDomainLimitUpgradeEmailSubject,
@Config("bulkPricingPackageCreateLimitEmailBody")
String bulkPricingPackageCreateLimitEmailBody,
@Config("bulkPricingPackageDomainLimitWarningEmailBody")
String bulkPricingPackageDomainLimitWarningEmailBody,
@Config("bulkPricingPackageDomainLimitUpgradeEmailBody")
String bulkPricingPackageDomainLimitUpgradeEmailBody,
@Config("registrySupportEmail") String registrySupportEmail) {
this.sendEmailUtils = sendEmailUtils;
this.clock = clock;
this.bulkPricingPackageCreateLimitEmailSubject = bulkPricingPackageCreateLimitEmailSubject;
this.bulkPricingPackageDomainLimitWarningEmailSubject =
bulkPricingPackageDomainLimitWarningEmailSubject;
this.bulkPricingPackageDomainLimitUpgradeEmailSubject =
bulkPricingPackageDomainLimitUpgradeEmailSubject;
this.bulkPricingPackageCreateLimitEmailBody = bulkPricingPackageCreateLimitEmailBody;
this.bulkPricingPackageDomainLimitWarningEmailBody =
bulkPricingPackageDomainLimitWarningEmailBody;
this.bulkPricingPackageDomainLimitUpgradeEmailBody =
bulkPricingPackageDomainLimitUpgradeEmailBody;
this.registrySupportEmail = registrySupportEmail;
}
@Override
public void run() {
tm().transact(this::checkBulkPackages);
}
private void checkBulkPackages() {
ImmutableList<BulkPricingPackage> bulkPricingPackages =
tm().loadAllOf(BulkPricingPackage.class);
ImmutableMap.Builder<BulkPricingPackage, Long> bulkPricingPackagesOverCreateLimitBuilder =
new ImmutableMap.Builder<>();
ImmutableMap.Builder<BulkPricingPackage, Long>
bulkPricingPackagesOverActiveDomainsLimitBuilder = new ImmutableMap.Builder<>();
for (BulkPricingPackage bulkPricingPackage : bulkPricingPackages) {
Long creates =
(Long)
tm().query(
"SELECT COUNT(*) FROM DomainHistory WHERE current_package_token ="
+ " :token AND modificationTime >= :lastBilling AND type ="
+ " 'DOMAIN_CREATE'")
.setParameter("token", bulkPricingPackage.getToken().getKey().toString())
.setParameter(
"lastBilling", bulkPricingPackage.getNextBillingDate().minusYears(1))
.getSingleResult();
if (creates > bulkPricingPackage.getMaxCreates()) {
long overage = creates - bulkPricingPackage.getMaxCreates();
logger.atInfo().log(
"Bulk pricing package with bulk token %s has exceeded their max domain creation limit"
+ " by %d name(s).",
bulkPricingPackage.getToken().getKey(), overage);
bulkPricingPackagesOverCreateLimitBuilder.put(bulkPricingPackage, creates);
}
Long activeDomains =
tm().query(
"SELECT COUNT(*) FROM Domain WHERE currentBulkToken = :token"
+ " AND deletionTime = :endOfTime",
Long.class)
.setParameter("token", bulkPricingPackage.getToken())
.setParameter("endOfTime", END_OF_TIME)
.getSingleResult();
if (activeDomains > bulkPricingPackage.getMaxDomains()) {
int overage = Ints.saturatedCast(activeDomains) - bulkPricingPackage.getMaxDomains();
logger.atInfo().log(
"Bulk pricing package with bulk token %s has exceed their max active domains limit by"
+ " %d name(s).",
bulkPricingPackage.getToken().getKey(), overage);
bulkPricingPackagesOverActiveDomainsLimitBuilder.put(bulkPricingPackage, activeDomains);
}
}
handleBulkPricingPackageCreationOverage(bulkPricingPackagesOverCreateLimitBuilder.build());
handleActiveDomainOverage(bulkPricingPackagesOverActiveDomainsLimitBuilder.build());
}
private void handleBulkPricingPackageCreationOverage(
ImmutableMap<BulkPricingPackage, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no bulk pricing packages over their create limit.");
return;
}
logger.atInfo().log(
"Found %d bulk pricing packages over their create limit.", overageList.size());
for (BulkPricingPackage bulkPricingPackage : overageList.keySet()) {
AllocationToken bulkToken = tm().loadByKey(bulkPricingPackage.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(bulkToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
bulkPricingPackageCreateLimitEmailBody,
bulkPricingPackage.getId(),
bulkToken.getToken(),
registrar.get().getRegistrarName(),
bulkPricingPackage.getMaxCreates(),
overageList.get(bulkPricingPackage));
sendNotification(
bulkToken, bulkPricingPackageCreateLimitEmailSubject, body, registrar.get());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for bulk token %s", bulkToken));
}
}
}
private void handleActiveDomainOverage(ImmutableMap<BulkPricingPackage, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no bulk pricing packages over their active domains limit.");
return;
}
logger.atInfo().log(
"Found %d bulk pricing packages over their active domains limit.", overageList.size());
for (BulkPricingPackage bulkPricingPackage : overageList.keySet()) {
int daysSinceLastNotification =
bulkPricingPackage
.getLastNotificationSent()
.map(sentDate -> Days.daysBetween(sentDate, clock.nowUtc()).getDays())
.orElse(Integer.MAX_VALUE);
if (daysSinceLastNotification < THIRTY_DAYS) {
// Don't send an email if notification was already sent within the last 30
// days
continue;
} else if (daysSinceLastNotification < FORTY_DAYS) {
// Send an upgrade email if last email was between 30 and 40 days ago
sendActiveDomainOverageEmail(
/* warning= */ false, bulkPricingPackage, overageList.get(bulkPricingPackage));
} else {
// Send a warning email
sendActiveDomainOverageEmail(
/* warning= */ true, bulkPricingPackage, overageList.get(bulkPricingPackage));
}
}
}
private void sendActiveDomainOverageEmail(
boolean warning, BulkPricingPackage bulkPricingPackage, long activeDomains) {
String emailSubject =
warning
? bulkPricingPackageDomainLimitWarningEmailSubject
: bulkPricingPackageDomainLimitUpgradeEmailSubject;
String emailTemplate =
warning
? bulkPricingPackageDomainLimitWarningEmailBody
: bulkPricingPackageDomainLimitUpgradeEmailBody;
AllocationToken bulkToken = tm().loadByKey(bulkPricingPackage.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(bulkToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
emailTemplate,
bulkPricingPackage.getId(),
bulkToken.getToken(),
registrar.get().getRegistrarName(),
bulkPricingPackage.getMaxDomains(),
activeDomains);
sendNotification(bulkToken, emailSubject, body, registrar.get());
tm().put(bulkPricingPackage.asBuilder().setLastNotificationSent(clock.nowUtc()).build());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for bulk token %s", bulkToken));
}
}
private void sendNotification(
AllocationToken bulkToken, String subject, String body, Registrar registrar) {
logger.atInfo().log(
String.format(
"Compliance email sent to support regarding the %s registrar and the bulk pricing"
+ " package with token %s.",
registrar.getRegistrarName(), bulkToken.getToken()));
sendEmailUtils.sendEmail(subject, body, ImmutableList.of(registrySupportEmail));
}
}
@@ -1,226 +0,0 @@
// Copyright 2022 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.batch;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.primitives.Ints;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.Action.Service;
import google.registry.request.auth.Auth;
import google.registry.ui.server.SendEmailUtils;
import google.registry.util.Clock;
import java.util.Optional;
import javax.inject.Inject;
import org.joda.time.Days;
/**
* An action that checks all {@link PackagePromotion} objects for compliance with their max create
* limit.
*/
@Action(
service = Service.BACKEND,
path = CheckPackagesComplianceAction.PATH,
auth = Auth.AUTH_API_ADMIN)
public class CheckPackagesComplianceAction implements Runnable {
public static final String PATH = "/_dr/task/checkPackagesCompliance";
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SendEmailUtils sendEmailUtils;
private final Clock clock;
private final String packageCreateLimitEmailSubject;
private final String packageDomainLimitWarningEmailSubject;
private final String packageDomainLimitUpgradeEmailSubject;
private final String packageCreateLimitEmailBody;
private final String packageDomainLimitWarningEmailBody;
private final String packageDomainLimitUpgradeEmailBody;
private final String registrySupportEmail;
private static final int THIRTY_DAYS = 30;
private static final int FORTY_DAYS = 40;
@Inject
public CheckPackagesComplianceAction(
SendEmailUtils sendEmailUtils,
Clock clock,
@Config("packageCreateLimitEmailSubject") String packageCreateLimitEmailSubject,
@Config("packageDomainLimitWarningEmailSubject") String packageDomainLimitWarningEmailSubject,
@Config("packageDomainLimitUpgradeEmailSubject") String packageDomainLimitUpgradeEmailSubject,
@Config("packageCreateLimitEmailBody") String packageCreateLimitEmailBody,
@Config("packageDomainLimitWarningEmailBody") String packageDomainLimitWarningEmailBody,
@Config("packageDomainLimitUpgradeEmailBody") String packageDomainLimitUpgradeEmailBody,
@Config("registrySupportEmail") String registrySupportEmail) {
this.sendEmailUtils = sendEmailUtils;
this.clock = clock;
this.packageCreateLimitEmailSubject = packageCreateLimitEmailSubject;
this.packageDomainLimitWarningEmailSubject = packageDomainLimitWarningEmailSubject;
this.packageDomainLimitUpgradeEmailSubject = packageDomainLimitUpgradeEmailSubject;
this.packageCreateLimitEmailBody = packageCreateLimitEmailBody;
this.packageDomainLimitWarningEmailBody = packageDomainLimitWarningEmailBody;
this.packageDomainLimitUpgradeEmailBody = packageDomainLimitUpgradeEmailBody;
this.registrySupportEmail = registrySupportEmail;
}
@Override
public void run() {
tm().transact(this::checkPackages);
}
private void checkPackages() {
ImmutableList<PackagePromotion> packages = tm().loadAllOf(PackagePromotion.class);
ImmutableMap.Builder<PackagePromotion, Long> packagesOverCreateLimitBuilder =
new ImmutableMap.Builder<>();
ImmutableMap.Builder<PackagePromotion, Long> packagesOverActiveDomainsLimitBuilder =
new ImmutableMap.Builder<>();
for (PackagePromotion packagePromo : packages) {
Long creates =
(Long)
tm().query(
"SELECT COUNT(*) FROM DomainHistory WHERE current_package_token ="
+ " :token AND modificationTime >= :lastBilling AND type ="
+ " 'DOMAIN_CREATE'")
.setParameter("token", packagePromo.getToken().getKey().toString())
.setParameter("lastBilling", packagePromo.getNextBillingDate().minusYears(1))
.getSingleResult();
if (creates > packagePromo.getMaxCreates()) {
long overage = creates - packagePromo.getMaxCreates();
logger.atInfo().log(
"Package with package token %s has exceeded their max domain creation limit"
+ " by %d name(s).",
packagePromo.getToken().getKey(), overage);
packagesOverCreateLimitBuilder.put(packagePromo, creates);
}
Long activeDomains =
tm().query(
"SELECT COUNT(*) FROM Domain WHERE currentPackageToken = :token"
+ " AND deletionTime = :endOfTime",
Long.class)
.setParameter("token", packagePromo.getToken())
.setParameter("endOfTime", END_OF_TIME)
.getSingleResult();
if (activeDomains > packagePromo.getMaxDomains()) {
int overage = Ints.saturatedCast(activeDomains) - packagePromo.getMaxDomains();
logger.atInfo().log(
"Package with package token %s has exceed their max active domains limit by"
+ " %d name(s).",
packagePromo.getToken().getKey(), overage);
packagesOverActiveDomainsLimitBuilder.put(packagePromo, activeDomains);
}
}
handlePackageCreationOverage(packagesOverCreateLimitBuilder.build());
handleActiveDomainOverage(packagesOverActiveDomainsLimitBuilder.build());
}
private void handlePackageCreationOverage(ImmutableMap<PackagePromotion, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no packages over their create limit.");
return;
}
logger.atInfo().log("Found %d packages over their create limit.", overageList.size());
for (PackagePromotion packagePromotion : overageList.keySet()) {
AllocationToken packageToken = tm().loadByKey(packagePromotion.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(packageToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
packageCreateLimitEmailBody,
packagePromotion.getId(),
packageToken.getToken(),
registrar.get().getRegistrarName(),
packagePromotion.getMaxCreates(),
overageList.get(packagePromotion));
sendNotification(packageToken, packageCreateLimitEmailSubject, body, registrar.get());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for package token %s", packageToken));
}
}
}
private void handleActiveDomainOverage(ImmutableMap<PackagePromotion, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no packages over their active domains limit.");
return;
}
logger.atInfo().log("Found %d packages over their active domains limit.", overageList.size());
for (PackagePromotion packagePromotion : overageList.keySet()) {
int daysSinceLastNotification =
packagePromotion
.getLastNotificationSent()
.map(sentDate -> Days.daysBetween(sentDate, clock.nowUtc()).getDays())
.orElse(Integer.MAX_VALUE);
if (daysSinceLastNotification < THIRTY_DAYS) {
// Don't send an email if notification was already sent within the last 30
// days
continue;
} else if (daysSinceLastNotification < FORTY_DAYS) {
// Send an upgrade email if last email was between 30 and 40 days ago
sendActiveDomainOverageEmail(
/* warning= */ false, packagePromotion, overageList.get(packagePromotion));
} else {
// Send a warning email
sendActiveDomainOverageEmail(
/* warning= */ true, packagePromotion, overageList.get(packagePromotion));
}
}
}
private void sendActiveDomainOverageEmail(
boolean warning, PackagePromotion packagePromotion, long activeDomains) {
String emailSubject =
warning ? packageDomainLimitWarningEmailSubject : packageDomainLimitUpgradeEmailSubject;
String emailTemplate =
warning ? packageDomainLimitWarningEmailBody : packageDomainLimitUpgradeEmailBody;
AllocationToken packageToken = tm().loadByKey(packagePromotion.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(packageToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
emailTemplate,
packagePromotion.getId(),
packageToken.getToken(),
registrar.get().getRegistrarName(),
packagePromotion.getMaxDomains(),
activeDomains);
sendNotification(packageToken, emailSubject, body, registrar.get());
tm().put(packagePromotion.asBuilder().setLastNotificationSent(clock.nowUtc()).build());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for package token %s", packageToken));
}
}
private void sendNotification(
AllocationToken packageToken, String subject, String body, Registrar registrar) {
logger.atInfo().log(
String.format(
"Compliance email sent to support regarding the %s registrar and the package with token"
+ " %s.",
registrar.getRegistrarName(), packageToken.getToken()));
sendEmailUtils.sendEmail(subject, body, ImmutableList.of(registrySupportEmail));
}
}
@@ -1,88 +0,0 @@
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.beam.common;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.flogger.FluentLogger;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
/**
* A database snapshot shareable by concurrent queries from multiple database clients. A snapshot is
* uniquely identified by its {@link #getSnapshotId snapshotId}, and must stay open until all
* concurrent queries to this snapshot have attached to it by calling {@link
* google.registry.persistence.transaction.JpaTransactionManager#setDatabaseSnapshot}. However, it
* can be closed before those queries complete.
*
* <p>This feature is <em>Postgresql-only</em>.
*
* <p>To support large queries, transaction isolation level is fixed at the REPEATABLE_READ to avoid
* exhausting predicate locks at the SERIALIZABLE level.
*/
// TODO(b/193662898): vendor-independent support for richer transaction semantics.
public class DatabaseSnapshot implements AutoCloseable {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private String snapshotId;
private EntityManager entityManager;
private EntityTransaction transaction;
private DatabaseSnapshot() {}
public String getSnapshotId() {
checkState(entityManager != null, "Snapshot not opened yet.");
checkState(entityManager.isOpen(), "Snapshot already closed.");
return snapshotId;
}
private DatabaseSnapshot open() {
entityManager = tm().getStandaloneEntityManager();
transaction = entityManager.getTransaction();
transaction.setRollbackOnly();
transaction.begin();
entityManager
.createNativeQuery("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ")
.executeUpdate();
List<?> snapshotIds =
entityManager.createNativeQuery("SELECT pg_export_snapshot();").getResultList();
checkState(snapshotIds.size() == 1, "Unexpected number of snapshots: %s", snapshotIds.size());
snapshotId = (String) snapshotIds.get(0);
return this;
}
@Override
public void close() {
if (transaction != null && transaction.isActive()) {
try {
transaction.rollback();
} catch (Exception e) {
logger.atWarning().withCause(e).log("Failed to close a Database Snapshot");
}
}
if (entityManager != null && entityManager.isOpen()) {
entityManager.close();
}
}
public static DatabaseSnapshot createSnapshot() {
return new DatabaseSnapshot().open();
}
}
@@ -122,6 +122,7 @@ public final class RegistryJpaIO {
@AutoValue
public abstract static class Read<R, T> extends PTransform<PBegin, PCollection<T>> {
private static final long serialVersionUID = 6906842877429561700L;
public static final String DEFAULT_NAME = "RegistryJpaIO.Read";
abstract String name();
@@ -133,9 +134,6 @@ public final class RegistryJpaIO {
@Nullable
abstract Coder<T> coder();
@Nullable
abstract String snapshotId();
abstract Builder<R, T> toBuilder();
@Override
@@ -145,8 +143,7 @@ public final class RegistryJpaIO {
input
.apply("Starting " + name(), Create.of((Void) null))
.apply(
"Run query for " + name(),
ParDo.of(new QueryRunner<>(query(), resultMapper(), snapshotId())));
"Run query for " + name(), ParDo.of(new QueryRunner<>(query(), resultMapper())));
if (coder() != null) {
output = output.setCoder(coder());
}
@@ -165,18 +162,6 @@ public final class RegistryJpaIO {
return toBuilder().coder(coder).build();
}
/**
* Specifies the database snapshot to use for this query.
*
* <p>This feature is <em>Postgresql-only</em>. User is responsible for keeping the snapshot
* available until all JVM workers have started using it by calling {@link
* JpaTransactionManager#setDatabaseSnapshot}.
*/
// TODO(b/193662898): vendor-independent support for richer transaction semantics.
public Read<R, T> withSnapshot(@Nullable String snapshotId) {
return toBuilder().snapshotId(snapshotId).build();
}
static <R, T> Builder<R, T> builder() {
return new AutoValue_RegistryJpaIO_Read.Builder<R, T>().name(DEFAULT_NAME);
}
@@ -192,8 +177,6 @@ public final class RegistryJpaIO {
abstract Builder<R, T> coder(Coder<T> coder);
abstract Builder<R, T> snapshotId(@Nullable String sharedSnapshotId);
abstract Read<R, T> build();
Builder<R, T> criteriaQuery(CriteriaQuerySupplier<R> criteriaQuery) {
@@ -214,27 +197,20 @@ public final class RegistryJpaIO {
}
static class QueryRunner<R, T> extends DoFn<Void, T> {
private static final long serialVersionUID = 7293891513058653334L;
private final RegistryQuery<R> query;
private final SerializableFunction<R, T> resultMapper;
// java.util.Optional is not serializable. Use of Guava Optional is discouraged.
@Nullable private final String snapshotId;
QueryRunner(
RegistryQuery<R> query,
SerializableFunction<R, T> resultMapper,
@Nullable String snapshotId) {
QueryRunner(RegistryQuery<R> query, SerializableFunction<R, T> resultMapper) {
this.query = query;
this.resultMapper = resultMapper;
this.snapshotId = snapshotId;
}
@ProcessElement
public void processElement(OutputReceiver<T> outputReceiver) {
tm().transactNoRetry(
() -> {
if (snapshotId != null) {
tm().setDatabaseSnapshot(snapshotId);
}
query.stream().map(resultMapper::apply).forEach(outputReceiver::output);
});
}
@@ -256,8 +232,8 @@ public final class RegistryJpaIO {
@AutoValue
public abstract static class Write<T> extends PTransform<PCollection<T>, PCollection<Void>> {
private static final long serialVersionUID = -4023583243078410323L;
public static final String DEFAULT_NAME = "RegistryJpaIO.Write";
public static final int DEFAULT_BATCH_SIZE = 1;
public abstract String name();
@@ -321,6 +297,8 @@ public final class RegistryJpaIO {
/** Writes a batch of entities to a SQL database through a {@link JpaTransactionManager}. */
private static class SqlBatchWriter<T> extends DoFn<KV<ShardedKey<Integer>, Iterable<T>>, Void> {
private static final long serialVersionUID = -7519944406319472690L;
private final Counter counter;
private final SerializableFunction<T, Object> jpaConverter;
@@ -337,7 +315,7 @@ public final class RegistryJpaIO {
private void actuallyProcessElement(@Element KV<ShardedKey<Integer>, Iterable<T>> kv) {
ImmutableList<Object> entities =
Streams.stream(kv.getValue())
.map(this.jpaConverter::apply)
.map(jpaConverter::apply)
// TODO(b/177340730): post migration delete the line below.
.filter(Objects::nonNull)
.collect(ImmutableList.toImmutableList());
@@ -373,7 +351,7 @@ public final class RegistryJpaIO {
}
/** Returns this entity's primary key field(s) in a string. */
private String toEntityKeyString(Object entity) {
private static String toEntityKeyString(Object entity) {
try {
return tm().transact(
() ->
@@ -93,13 +93,56 @@ public abstract class CredentialModule {
@AdcDelegatedCredential
@Provides
@Singleton
public static GoogleCredentialsBundle provideSelfSignedDelegatedCredential(
public static GoogleCredentialsBundle provideSelfSignedAdminDelegatedCredential(
@Config("defaultCredentialOauthScopes") ImmutableList<String> defaultScopes,
@Config("delegatedCredentialOauthScopes") ImmutableList<String> delegationScopes,
@ApplicationDefaultCredential GoogleCredentialsBundle credentialsBundle,
@Config("gSuiteAdminAccountEmailAddress") String gSuiteAdminAccountEmailAddress,
@Config("tokenRefreshDelay") Duration tokenRefreshDelay,
Clock clock) {
return createSelfSignedDelegatedCredential(
defaultScopes,
delegationScopes,
credentialsBundle,
gSuiteAdminAccountEmailAddress,
tokenRefreshDelay,
clock);
}
/**
* Provides a {@link GoogleCredentialsBundle} for sending emails through Google Workspace.
*
* <p>The Workspace domain must grant delegated admin access to the default service account user
* (project-id@appspot.gserviceaccount.com on AppEngine) with all scopes in {@code defaultScopes}
* and {@code delegationScopes}. In addition, the user {@code gSuiteOutgoingEmailAddress} must
* have the permission to send emails.
*/
@GmailDelegatedCredential
@Provides
@Singleton
public static GoogleCredentialsBundle provideSelfSignedGmailDelegatedCredential(
@Config("defaultCredentialOauthScopes") ImmutableList<String> defaultScopes,
@Config("delegatedCredentialOauthScopes") ImmutableList<String> delegationScopes,
@ApplicationDefaultCredential GoogleCredentialsBundle credentialsBundle,
@Config("gSuiteNewOutgoingEmailAddress") String gSuiteOutgoingEmailAddress,
@Config("tokenRefreshDelay") Duration tokenRefreshDelay,
Clock clock) {
return createSelfSignedDelegatedCredential(
defaultScopes,
delegationScopes,
credentialsBundle,
gSuiteOutgoingEmailAddress,
tokenRefreshDelay,
clock);
}
public static GoogleCredentialsBundle createSelfSignedDelegatedCredential(
ImmutableList<String> defaultScopes,
ImmutableList<String> delegationScopes,
GoogleCredentialsBundle credentialsBundle,
String gSuiteUserEmailAddress,
Duration tokenRefreshDelay,
Clock clock) {
GoogleCredentials signer = credentialsBundle.getGoogleCredentials();
checkArgument(
@@ -118,7 +161,7 @@ public abstract class CredentialModule {
DelegatedCredentials.createSelfSignedDelegatedCredential(
(ServiceAccountSigner) signer,
ImmutableList.<String>builder().addAll(defaultScopes).addAll(delegationScopes).build(),
gSuiteAdminAccountEmailAddress,
gSuiteUserEmailAddress,
clock,
tokenRefreshDelay);
return GoogleCredentialsBundle.create(credential);
@@ -136,6 +179,15 @@ public abstract class CredentialModule {
@Retention(RetentionPolicy.RUNTIME)
public @interface GoogleWorkspaceCredential {}
/**
* Dagger qualifier for a credential with delegated Email-sending permission for a dasher domain
* (for Google Workspace) backed by the application default credential (ADC).
*/
@Qualifier
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface GmailDelegatedCredential {}
/**
* Dagger qualifier for a credential with delegated admin access for a dasher domain (for Google
* Workspace) backed by the application default credential (ADC).
@@ -158,6 +158,12 @@ public final class RegistryConfig {
return config.registryPolicy.contactAndHostRoidSuffix;
}
@Provides
@Config("isEmailSendingEnabled")
public static boolean provideIsEmailSendingEnabled(RegistryConfigSettings config) {
return config.misc.isEmailSendingEnabled;
}
/**
* The e-mail address for questions about integrating with the registry. Used in the
* "contact-us" section of the registrar console.
@@ -538,6 +544,13 @@ public final class RegistryConfig {
return parseEmailAddress(config.gSuite.outgoingEmailAddress);
}
// TODO(b/279671974): reuse the 'gSuiteOutgoingEmailAddress' annotation after migration
@Provides
@Config("gSuiteNewOutgoingEmailAddress")
public static String provideGSuiteNewOutgoingEmailAddress(RegistryConfigSettings config) {
return config.gSuite.newOutgoingEmailAddress;
}
/**
* The display name that is used on outgoing emails sent by Nomulus.
*
@@ -549,6 +562,16 @@ public final class RegistryConfig {
return config.gSuite.outgoingEmailDisplayName;
}
/**
* Provides the `reply-to` address for outgoing email messages. This address may be outside the
* GSuite domain.
*/
@Provides
@Config("replyToEmailAddress")
public static InternetAddress provideReplyToEmailAddress(RegistryConfigSettings config) {
return parseEmailAddress(config.gSuite.replyToEmailAddress);
}
/**
* Returns whether an SSL certificate hash is required to log in via EPP and run flows.
*
@@ -859,6 +882,14 @@ public final class RegistryConfig {
return parseEmailAddress(config.misc.alertRecipientEmailAddress);
}
// TODO(b/279671974): remove below method after migration
@Provides
@Config("newAlertRecipientEmailAddress")
public static InternetAddress provideNewAlertRecipientEmailAddress(
RegistryConfigSettings config) {
return parseEmailAddress(config.misc.newAlertRecipientEmailAddress);
}
/**
* Returns the email address to which spec 11 email should be replied.
*
@@ -1340,41 +1371,45 @@ public final class RegistryConfig {
}
@Provides
@Config("packageCreateLimitEmailSubject")
public static String providePackageCreateLimitEmailSubject(RegistryConfigSettings config) {
return config.packageMonitoring.packageCreateLimitEmailSubject;
}
@Provides
@Config("packageCreateLimitEmailBody")
public static String providePackageCreateLimitEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageCreateLimitEmailBody;
}
@Provides
@Config("packageDomainLimitWarningEmailSubject")
public static String providePackageDomainLimitWarningEmailSubject(
@Config("bulkPricingPackageCreateLimitEmailSubject")
public static String provideBulkPricingPackageCreateLimitEmailSubject(
RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitWarningEmailSubject;
return config.bulkPricingPackageMonitoring.bulkPricingPackageCreateLimitEmailSubject;
}
@Provides
@Config("packageDomainLimitWarningEmailBody")
public static String providePackageDomainLimitWarningEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitWarningEmailBody;
}
@Provides
@Config("packageDomainLimitUpgradeEmailSubject")
public static String providePackageDomainLimitUpgradeEmailSubject(
@Config("bulkPricingPackageCreateLimitEmailBody")
public static String provideBulkPricingPackageCreateLimitEmailBody(
RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitUpgradeEmailSubject;
return config.bulkPricingPackageMonitoring.bulkPricingPackageCreateLimitEmailBody;
}
@Provides
@Config("packageDomainLimitUpgradeEmailBody")
public static String providePackageDomainLimitUpgradeEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitUpgradeEmailBody;
@Config("bulkPricingPackageDomainLimitWarningEmailSubject")
public static String provideBulkPricingPackageDomainLimitWarningEmailSubject(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitWarningEmailSubject;
}
@Provides
@Config("bulkPricingPackageDomainLimitWarningEmailBody")
public static String provideBulkPricingPackageDomainLimitWarningEmailBody(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitWarningEmailBody;
}
@Provides
@Config("bulkPricingPackageDomainLimitUpgradeEmailSubject")
public static String provideBulkPricingPackageDomainLimitUpgradeEmailSubject(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitUpgradeEmailSubject;
}
@Provides
@Config("bulkPricingPackageDomainLimitUpgradeEmailBody")
public static String provideBulkPricingPackageDomainLimitUpgradeEmailBody(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitUpgradeEmailBody;
}
private static String formatComments(String text) {
@@ -1516,6 +1551,11 @@ public final class RegistryConfig {
return CONFIG_SETTINGS.get().hibernate.connectionIsolation;
}
/** Returns true if per-transaction isolation level is enabled. */
public static boolean getHibernatePerTransactionIsolationEnabled() {
return CONFIG_SETTINGS.get().hibernate.perTransactionIsolation;
}
/** Returns true if hibernate.show_sql is enabled. */
public static String getHibernateLogSqlQueries() {
return CONFIG_SETTINGS.get().hibernate.logSqlQueries;
@@ -42,7 +42,7 @@ public class RegistryConfigSettings {
public SslCertificateValidation sslCertificateValidation;
public ContactHistory contactHistory;
public DnsUpdate dnsUpdate;
public PackageMonitoring packageMonitoring;
public BulkPricingPackageMonitoring bulkPricingPackageMonitoring;
/** Configuration options that apply to the entire GCP project. */
public static class GcpProject {
@@ -77,6 +77,9 @@ public class RegistryConfigSettings {
public static class GSuite {
public String domainName;
public String outgoingEmailAddress;
// TODO(b/279671974): remove below field after migration
public String newOutgoingEmailAddress;
public String replyToEmailAddress;
public String outgoingEmailDisplayName;
public String adminAccountEmailAddress;
public String supportGroupEmailAddress;
@@ -112,6 +115,7 @@ public class RegistryConfigSettings {
/** Configuration for Hibernate. */
public static class Hibernate {
public boolean perTransactionIsolation;
public String connectionIsolation;
public String logSqlQueries;
public String hikariConnectionTimeout;
@@ -202,7 +206,10 @@ public class RegistryConfigSettings {
/** Miscellaneous configuration that doesn't quite fit in anywhere else. */
public static class Misc {
public String sheetExportId;
public boolean isEmailSendingEnabled;
public String alertRecipientEmailAddress;
// TODO(b/279671974): remove below field after migration
public String newAlertRecipientEmailAddress;
public String spec11OutgoingEmailAddress;
public List<String> spec11BccEmailAddresses;
public int transientFailureRetries;
@@ -246,13 +253,13 @@ public class RegistryConfigSettings {
public String registryCcEmail;
}
/** Configuration for package compliance monitoring. */
public static class PackageMonitoring {
public String packageCreateLimitEmailSubject;
public String packageCreateLimitEmailBody;
public String packageDomainLimitWarningEmailSubject;
public String packageDomainLimitWarningEmailBody;
public String packageDomainLimitUpgradeEmailSubject;
public String packageDomainLimitUpgradeEmailBody;
/** Configuration for bulk pricing package compliance monitoring. */
public static class BulkPricingPackageMonitoring {
public String bulkPricingPackageCreateLimitEmailSubject;
public String bulkPricingPackageCreateLimitEmailBody;
public String bulkPricingPackageDomainLimitWarningEmailSubject;
public String bulkPricingPackageDomainLimitWarningEmailBody;
public String bulkPricingPackageDomainLimitUpgradeEmailSubject;
public String bulkPricingPackageDomainLimitUpgradeEmailBody;
}
}
@@ -33,6 +33,9 @@ gSuite:
# https://cloud.google.com/appengine/docs/standard/java/mail/#who_can_send_mail
outgoingEmailDisplayName: Example Registry
outgoingEmailAddress: noreply@project-id.appspotmail.com
# TODO(b/279671974): reuse `outgoingEmailAddress` after migration
newOutgoingEmailAddress: noreply@example.com
replyToEmailAddress: reply-to@example.com
# Email address of the admin account on the G Suite app. This is used for
# logging in to perform administrative actions, not sending emails.
@@ -186,6 +189,12 @@ registryPolicy:
sunriseDomainCreateDiscount: 0.15
hibernate:
# Make it possible to specify the isolation level for each transaction. If set
# to true, nested transactions will throw an exception. If set to false, a
# transaction with the isolation override specified will still execute at the
# default level (specified below).
perTransactionIsolation: false
# Make 'SERIALIZABLE' the default isolation level to ensure correctness.
#
# Entities that are never involved in multi-table transactions may use optimistic
@@ -429,9 +438,15 @@ misc:
# to. Leave this null to disable syncing.
sheetExportId: null
# Whether emails may be sent. For Prod and Sandbox this should be true.
isEmailSendingEnabled: false
# Address we send alert summary emails to.
alertRecipientEmailAddress: email@example.com
# TODO(b/279671974): reuse `alertRecipientEmailAddress` after migration
newAlertRecipientEmailAddress: email@example.com
# Address from which Spec 11 emails to registrars are sent. This needs
# to be a deliverable email address to handle replies from registrars as well.
spec11OutgoingEmailAddress: abuse@example.com
@@ -470,7 +485,7 @@ keyring:
# Configuration options relevant to the "nomulus" registry tool.
registryTool:
# OAuth client Id used by the tool.
# OAuth client ID used by the tool.
clientId: YOUR_CLIENT_ID
# OAuth client secret used by the tool.
clientSecret: YOUR_CLIENT_SECRET
@@ -544,55 +559,55 @@ sslCertificateValidation:
- secp256r1
- secp384r1
# Configuration options for the package compliance monitoring
packageMonitoring:
# Email subject text to notify tech support that a package has exceeded the limit for domain creates
packageCreateLimitEmailSubject: "ACTION REQUIRED: Package needs to be upgraded"
# Email body text template notify support that a package has exceeded the limit for domain creates
packageCreateLimitEmailBody: >
# Configuration options for the bulk pricing package compliance monitoring
bulkPricingPackageMonitoring:
# Email subject text to notify tech support that a bulk pricing package has exceeded the limit for domain creates
bulkPricingPackageCreateLimitEmailSubject: "ACTION REQUIRED: Bulk pricing package needs to be upgraded"
# Email body text template notify support that a bulk pricing package has exceeded the limit for domain creates
bulkPricingPackageCreateLimitEmailBody: >
Dear Support,
A package has exceeded its max create limit and needs to be upgraded to the
A bulk pricing package has exceeded its max create limit and needs to be upgraded to the
next tier.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Current Max Create Limit: %4$s
Creates Completed: %5$s
# Email subject text to notify support that a package has exceeded the limit
# Email subject text to notify support that a bulk pricing package has exceeded the limit
# for current active domains and a warning needs to be sent
packageDomainLimitWarningEmailSubject: "ACTION REQUIRED: Package has exceeded the domain limit - send warning"
# Email body text template to inform support that a package has exceeded the
# limit for active domains and a warning needs to be sent that the package
bulkPricingPackageDomainLimitWarningEmailSubject: "ACTION REQUIRED: Bulk pricing package has exceeded the domain limit - send warning"
# Email body text template to inform support that a bulk pricing package has exceeded the
# limit for active domains and a warning needs to be sent that the bulk pricing package
# will be upgraded in 30 days
packageDomainLimitWarningEmailBody: >
bulkPricingPackageDomainLimitWarningEmailBody: >
Dear Support,
A package has exceeded its max domain limit. Please send a warning to the
registrar that their package will be upgraded to the next tier in 30 days if
A bulk pricing package has exceeded its max domain limit. Please send a warning to the
registrar that their bulk pricing package will be upgraded to the next tier in 30 days if
the number of active domains does not return below the limit.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Active Domain Limit: %4$s
Current Active Domains: %5$s
# Email subject text to notify support that a package has exceeded the limit
# Email subject text to notify support that a bulk pricing package has exceeded the limit
# for current active domains for more than 30 days and needs to be upgraded
packageDomainLimitUpgradeEmailSubject: "ACTION REQUIRED: Package has exceeded the domain limit - upgrade package"
# Email body text template to inform support that a package has exceeded the
bulkPricingPackageDomainLimitUpgradeEmailSubject: "ACTION REQUIRED: Bulk pricing package has exceeded the domain limit - upgrade package"
# Email body text template to inform support that a bulk pricing package has exceeded the
# limit for active domains for more than 30 days and needs to be upgraded
packageDomainLimitUpgradeEmailBody: >
bulkPricingPackageDomainLimitUpgradeEmailBody: >
Dear Support,
A package has exceeded its max domain limit for over 30 days and needs to be
A bulk pricing package has exceeded its max domain limit for over 30 days and needs to be
upgraded to the next tier.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Active Domain Limit: %4$s
Current Active Domains: %5$s
@@ -26,3 +26,6 @@ gSuite:
misc:
# We would rather have failures than timeouts, so reduce the number of retries
transientFailureRetries: 3
hibernate:
perTransactionIsolation: false
@@ -7,7 +7,7 @@
<sessions-enabled>true</sessions-enabled>
<instance-class>B4_1G</instance-class>
<manual-scaling>
<instances>12</instances>
<instances>24</instances>
</manual-scaling>
<system-properties>
@@ -35,6 +35,8 @@ import google.registry.model.eppoutput.EppResponse;
import google.registry.model.eppoutput.Result;
import google.registry.model.host.HostHistory;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.IsolationLevel;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import java.lang.annotation.Documented;
import java.util.Optional;
import javax.inject.Qualifier;
@@ -135,6 +137,14 @@ public class FlowModule {
return TransactionalFlow.class.isAssignableFrom(flowClass);
}
@Provides
@FlowScope
Optional<TransactionIsolationLevel> provideIsolationLevelOverride(
Class<? extends Flow> flowClass) {
return Optional.ofNullable(flowClass.getAnnotation(IsolationLevel.class))
.map(IsolationLevel::value);
}
@Provides
@FlowScope
@Superuser
@@ -166,7 +176,7 @@ public class FlowModule {
@FlowScope
@RegistrarId
static String provideRegistrarId(SessionMetadata sessionMetadata) {
// Treat a missing registrarId as null so we can always inject a non-null value. All we do with
// Treat a missing registrarId as null, so we can always inject a non-null value. All we do with
// the registrarId is log it (as "") or detect its absence, both of which work fine with empty.
return Strings.nullToEmpty(sessionMetadata.getRegistrarId());
}
@@ -28,6 +28,8 @@ import google.registry.flows.session.LoginFlow;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppoutput.EppOutput;
import google.registry.monitoring.whitebox.EppMetric;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -42,6 +44,7 @@ public class FlowRunner {
@Inject TransportCredentials credentials;
@Inject EppRequestSource eppRequestSource;
@Inject Provider<Flow> flowProvider;
@Inject Optional<TransactionIsolationLevel> isolationLevelOverride;
@Inject Class<? extends Flow> flowClass;
@Inject @InputXml byte[] inputXmlBytes;
@Inject @DryRun boolean isDryRun;
@@ -91,7 +94,8 @@ public class FlowRunner {
} catch (EppException e) {
throw new EppRuntimeException(e);
}
});
},
isolationLevelOverride.orElse(null));
} catch (DryRunException e) {
return e.output;
} catch (EppRuntimeException e) {
@@ -152,7 +152,7 @@ import org.joda.time.Duration;
* @error {@link DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException}
* @error {@link DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException}
* @error {@link DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException}
* @error {@link DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException}
* @error {@link BulkDomainRegisteredForTooManyYearsException}
* @error {@link DomainCreateFlow.SignedMarksOnlyDuringSunriseException}
* @error {@link DomainFlowTmchUtils.NoMarksFoundMatchingDomainException}
* @error {@link DomainFlowTmchUtils.FoundMarkNotYetValidException}
@@ -405,12 +405,11 @@ public final class DomainCreateFlow implements TransactionalFlow {
: hasClaimsNotice ? LordnPhase.CLAIMS : LordnPhase.NONE);
Domain domain = domainBuilder.build();
if (allocationToken.isPresent()
&& allocationToken.get().getTokenType().equals(TokenType.PACKAGE)) {
&& allocationToken.get().getTokenType().equals(TokenType.BULK_PRICING)) {
if (years > 1) {
throw new PackageDomainRegisteredForTooManyYearsException(allocationToken.get().getToken());
throw new BulkDomainRegisteredForTooManyYearsException(allocationToken.get().getToken());
}
domain =
domain.asBuilder().setCurrentPackageToken(allocationToken.get().createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.get().createVKey()).build();
}
DomainHistory domainHistory =
buildDomainHistory(domain, tld, now, period, tld.getAddGracePeriodLength());
@@ -763,13 +762,12 @@ public final class DomainCreateFlow implements TransactionalFlow {
}
}
/** Package domain registered for too many years. */
static class PackageDomainRegisteredForTooManyYearsException extends CommandUseErrorException {
public PackageDomainRegisteredForTooManyYearsException(String token) {
/** Bulk pricing domain registered for too many years. */
static class BulkDomainRegisteredForTooManyYearsException extends CommandUseErrorException {
public BulkDomainRegisteredForTooManyYearsException(String token) {
super(
String.format(
"The package token %s cannot be used to register names for longer than 1 year.",
token));
"The bulk token %s cannot be used to register names for longer than 1 year.", token));
}
}
}
@@ -41,10 +41,10 @@ import google.registry.model.domain.Domain;
import google.registry.model.domain.DomainCommand.Info;
import google.registry.model.domain.DomainCommand.Info.HostsRequest;
import google.registry.model.domain.DomainInfoData;
import google.registry.model.domain.bulktoken.BulkTokenExtension;
import google.registry.model.domain.bulktoken.BulkTokenResponseExtension;
import google.registry.model.domain.fee06.FeeInfoCommandExtensionV06;
import google.registry.model.domain.fee06.FeeInfoResponseExtensionV06;
import google.registry.model.domain.packagetoken.PackageTokenExtension;
import google.registry.model.domain.packagetoken.PackageTokenResponseExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.rgp.RgpInfoExtension;
import google.registry.model.eppcommon.AuthInfo;
@@ -95,7 +95,7 @@ public final class DomainInfoFlow implements Flow {
@Override
public EppResponse run() throws EppException {
extensionManager.register(FeeInfoCommandExtensionV06.class, PackageTokenExtension.class);
extensionManager.register(FeeInfoCommandExtensionV06.class, BulkTokenExtension.class);
flowCustomLogic.beforeValidation();
validateRegistrarIsLoggedIn(registrarId);
extensionManager.validate();
@@ -155,13 +155,13 @@ public final class DomainInfoFlow implements Flow {
if (!gracePeriodStatuses.isEmpty()) {
extensions.add(RgpInfoExtension.create(gracePeriodStatuses));
}
Optional<PackageTokenExtension> packageInfo =
eppInput.getSingleExtension(PackageTokenExtension.class);
if (packageInfo.isPresent()) {
// Package info was requested.
Optional<BulkTokenExtension> bulkPricingInfo =
eppInput.getSingleExtension(BulkTokenExtension.class);
if (bulkPricingInfo.isPresent()) {
// Bulk pricing info was requested.
if (isSuperuser || registrarId.equals(domain.getCurrentSponsorRegistrarId())) {
// Only show package info to owning registrar or superusers
extensions.add(PackageTokenResponseExtension.create(domain.getCurrentPackageToken()));
// Only show bulk pricing info to owning registrar or superusers
extensions.add(BulkTokenResponseExtension.create(domain.getCurrentBulkToken()));
}
}
Optional<FeeInfoCommandExtensionV06> feeInfo =
@@ -30,7 +30,7 @@ import static google.registry.flows.domain.DomainFlowUtils.validateFeeChallenge;
import static google.registry.flows.domain.DomainFlowUtils.validateRegistrationPeriod;
import static google.registry.flows.domain.DomainFlowUtils.verifyRegistrarIsActive;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.maybeApplyPackageRemovalToken;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.maybeApplyBulkPricingRemovalToken;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.verifyTokenAllowedOnDomain;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_RENEW;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -53,6 +53,8 @@ import google.registry.flows.custom.DomainRenewFlowCustomLogic.BeforeResponseRet
import google.registry.flows.custom.DomainRenewFlowCustomLogic.BeforeSaveParameters;
import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.token.AllocationTokenFlowUtils;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnBulkPricingDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonBulkPricingDomainException;
import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingBase.Reason;
import google.registry.model.billing.BillingEvent;
@@ -119,10 +121,8 @@ import org.joda.time.Duration;
* @error {@link DomainFlowUtils.RegistrarMustBeActiveForThisOperationException}
* @error {@link DomainFlowUtils.UnsupportedFeeAttributeException}
* @error {@link DomainRenewFlow.IncorrectCurrentExpirationDateException}
* @error {@link
* google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemovePackageTokenOnPackageDomainException}
* @error {@link
* google.registry.flows.domain.token.AllocationTokenFlowUtils.RemovePackageTokenOnNonPackageDomainException}
* @error {@link MissingRemoveDomainTokenOnBulkPricingDomainException}
* @error {@link RemoveDomainTokenOnNonBulkPricingDomainException}
* @error {@link
* google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForDomainException}
* @error {@link
@@ -194,7 +194,7 @@ public final class DomainRenewFlow implements TransactionalFlow {
verifyRenewAllowed(authInfo, existingDomain, command, allocationToken);
// If client passed an applicable static token this updates the domain
existingDomain = maybeApplyPackageRemovalToken(existingDomain, allocationToken);
existingDomain = maybeApplyBulkPricingRemovalToken(existingDomain, allocationToken);
int years = command.getPeriod().getValue();
DateTime newExpirationTime =
@@ -328,7 +328,7 @@ public final class DomainRenewFlow implements TransactionalFlow {
checkHasBillingAccount(registrarId, existingDomain.getTld());
}
verifyUnitIsYears(command.getPeriod());
// We only allow __REMOVE_PACKAGE__ token on promo package domains for now
// We only allow __REMOVE_PACKAGE__ token on bulk pricing domains for now
verifyTokenAllowedOnDomain(existingDomain, allocationToken);
// If the date they specify doesn't match the expiration, fail. (This is an idempotence check).
if (!command.getCurrentExpirationDate().equals(
@@ -154,9 +154,9 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
tm().loadByKey(existingDomain.getAutorenewBillingEvent());
HistoryEntryId domainHistoryId = createHistoryEntryId(existingDomain);
historyBuilder.setRevisionId(domainHistoryId.getRevisionId());
boolean hasPackageToken = existingDomain.getCurrentPackageToken().isPresent();
boolean hasBulkToken = existingDomain.getCurrentBulkToken().isPresent();
Money renewalPrice =
hasPackageToken ? null : existingBillingRecurrence.getRenewalPrice().orElse(null);
hasBulkToken ? null : existingBillingRecurrence.getRenewalPrice().orElse(null);
Optional<BillingEvent> billingEvent =
transferData.getTransferPeriod().getValue() == 0
? Optional.empty()
@@ -172,10 +172,10 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
Tld.get(tldStr),
targetId,
transferData.getTransferRequestTime(),
// When removing a domain from a package it should return to the
// When removing a domain from bulk pricing it should return to the
// default recurrence billing behavior so the existing recurrence
// billing event should not be passed in.
hasPackageToken ? null : existingBillingRecurrence)
hasBulkToken ? null : existingBillingRecurrence)
.getRenewCost())
.setEventTime(now)
.setBillingTime(now.plus(Tld.get(tldStr).getTransferGracePeriodLength()))
@@ -213,7 +213,7 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
.setRegistrarId(gainingRegistrarId)
.setEventTime(newExpirationTime)
.setRenewalPriceBehavior(
hasPackageToken
hasBulkToken
? RenewalPriceBehavior.DEFAULT
: existingBillingRecurrence.getRenewalPriceBehavior())
.setRenewalPrice(renewalPrice)
@@ -258,9 +258,9 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
.orElseGet(ImmutableSet::of))
.setLastEppUpdateTime(now)
.setLastEppUpdateRegistrarId(registrarId)
// Even if the existing domain had a package token, that package token should be removed
// Even if the existing domain had a bulk token, that bulk token should be removed
// on transfer
.setCurrentPackageToken(null)
.setCurrentBulkToken(null)
.build();
Tld tld = Tld.get(existingDomain.getTld());
@@ -201,11 +201,12 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
Optional<FeesAndCredits> feesAndCredits;
if (period.getValue() == 0) {
feesAndCredits = Optional.empty();
} else if (!existingDomain.getCurrentPackageToken().isPresent()) {
} else if (!existingDomain.getCurrentBulkToken().isPresent()) {
feesAndCredits =
Optional.of(pricingLogic.getTransferPrice(tld, targetId, now, existingBillingRecurrence));
} else {
// If existing domain is in a package, calculate the transfer price with default renewal price
// If existing domain is in a bulk pricing package, calculate the transfer price with default
// renewal price
// behavior
feesAndCredits =
period.getValue() == 0
@@ -146,7 +146,7 @@ public final class DomainTransferUtils {
return builder
.add(
createGainingClientAutorenewEvent(
existingDomain.getCurrentPackageToken().isPresent()
existingDomain.getCurrentBulkToken().isPresent()
? existingBillingRecurrence
.asBuilder()
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT)
@@ -242,22 +242,22 @@ public class AllocationTokenFlowUtils {
public static void verifyTokenAllowedOnDomain(
Domain domain, Optional<AllocationToken> allocationToken) throws EppException {
boolean domainHasPackageToken = domain.getCurrentPackageToken().isPresent();
boolean hasRemovePackageToken =
boolean domainHasBulkToken = domain.getCurrentBulkToken().isPresent();
boolean hasRemoveDomainToken =
allocationToken.isPresent()
&& TokenBehavior.REMOVE_PACKAGE.equals(allocationToken.get().getTokenBehavior());
&& TokenBehavior.REMOVE_DOMAIN.equals(allocationToken.get().getTokenBehavior());
if (hasRemovePackageToken && !domainHasPackageToken) {
throw new RemovePackageTokenOnNonPackageDomainException();
} else if (!hasRemovePackageToken && domainHasPackageToken) {
throw new MissingRemovePackageTokenOnPackageDomainException();
if (hasRemoveDomainToken && !domainHasBulkToken) {
throw new RemoveDomainTokenOnNonBulkPricingDomainException();
} else if (!hasRemoveDomainToken && domainHasBulkToken) {
throw new MissingRemoveDomainTokenOnBulkPricingDomainException();
}
}
public static Domain maybeApplyPackageRemovalToken(
public static Domain maybeApplyBulkPricingRemovalToken(
Domain domain, Optional<AllocationToken> allocationToken) {
if (!allocationToken.isPresent()
|| !TokenBehavior.REMOVE_PACKAGE.equals(allocationToken.get().getTokenBehavior())) {
|| !TokenBehavior.REMOVE_DOMAIN.equals(allocationToken.get().getTokenBehavior())) {
return domain;
}
@@ -274,10 +274,10 @@ public class AllocationTokenFlowUtils {
tm().getEntityManager().flush();
tm().getEntityManager().clear();
// Remove current package token
// Remove current bulk token
return domain
.asBuilder()
.setCurrentPackageToken(null)
.setCurrentBulkToken(null)
.setAutorenewBillingEvent(newBillingRecurrence.createVKey())
.build();
}
@@ -338,19 +338,19 @@ public class AllocationTokenFlowUtils {
}
}
/** The __REMOVEPACKAGE__ token is missing on a package domain command */
public static class MissingRemovePackageTokenOnPackageDomainException
/** The __REMOVEDOMAIN__ token is missing on a bulk pricing domain command */
public static class MissingRemoveDomainTokenOnBulkPricingDomainException
extends AssociationProhibitsOperationException {
MissingRemovePackageTokenOnPackageDomainException() {
super("Domains that are inside packages cannot be explicitly renewed or transferred");
MissingRemoveDomainTokenOnBulkPricingDomainException() {
super("Domains that are inside bulk pricing cannot be explicitly renewed or transferred");
}
}
/** The __REMOVEPACKAGE__ token is not allowed on non package domains */
public static class RemovePackageTokenOnNonPackageDomainException
/** The __REMOVEDOMAIN__ token is not allowed on non bulk pricing domains */
public static class RemoveDomainTokenOnNonBulkPricingDomainException
extends AssociationProhibitsOperationException {
RemovePackageTokenOnNonPackageDomainException() {
super("__REMOVEPACKAGE__ token is not allowed on non package domains");
RemoveDomainTokenOnNonBulkPricingDomainException() {
super("__REMOVEDOMAIN__ token is not allowed on non bulk pricing domains");
}
}
}
@@ -14,17 +14,24 @@
package google.registry.groups;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.toArray;
import com.google.api.client.http.HttpResponseException;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.model.Message;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import google.registry.config.RegistryConfig.Config;
import google.registry.util.EmailMessage;
import google.registry.util.EmailMessage.Attachment;
import google.registry.util.Retrier;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import java.util.function.Predicate;
import javax.inject.Inject;
import javax.mail.Address;
import javax.mail.BodyPart;
@@ -36,16 +43,37 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.commons.codec.binary.Base64;
/** Sends {@link EmailMessage EmailMessages} through Google Workspace using {@link Gmail}. */
public final class GmailClient {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Gmail gmail;
private final Retrier retrier;
private final boolean isEmailSendingEnabled;
private final InternetAddress outgoingEmailAddressWithUsername;
private final InternetAddress replyToEmailAddress;
@Inject
GmailClient(Gmail gmail) {
GmailClient(
Gmail gmail,
Retrier retrier,
@Config("isEmailSendingEnabled") boolean isEmailSendingEnabled,
@Config("gSuiteNewOutgoingEmailAddress") String gSuiteOutgoingEmailAddress,
@Config("gSuiteOutgoingEmailDisplayName") String gSuiteOutgoingEmailDisplayName,
@Config("replyToEmailAddress") InternetAddress replyToEmailAddress) {
this.gmail = gmail;
this.retrier = retrier;
this.isEmailSendingEnabled = isEmailSendingEnabled;
this.replyToEmailAddress = replyToEmailAddress;
try {
this.outgoingEmailAddressWithUsername =
new InternetAddress(gSuiteOutgoingEmailAddress, gSuiteOutgoingEmailDisplayName);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
@@ -54,14 +82,25 @@ public final class GmailClient {
* <p>If the sender as specified by {@link EmailMessage#from} differs from the caller's identity,
* the caller must have delegated `send` authority to the sender.
*/
@CanIgnoreReturnValue
public Message sendEmail(EmailMessage emailMessage) {
Message message = toGmailMessage(toMimeMessage(emailMessage));
try {
return gmail.users().messages().send("me", message).execute();
} catch (IOException e) {
throw new EmailException(e);
public void sendEmail(EmailMessage emailMessage) {
if (!isEmailSendingEnabled) {
logger.atInfo().log(
String.format(
"Email with subject %s would have been sent to recipients %s",
emailMessage.subject().substring(0, Math.min(emailMessage.subject().length(), 15)),
String.join(
" , ",
emailMessage.recipients().stream()
.map(ia -> ia.toString())
.collect(toImmutableSet()))));
return;
}
Message message = toGmailMessage(toMimeMessage(emailMessage));
// Unlike other Cloud APIs such as GCS and SecretManager, Gmail does not retry on errors.
retrier.callWithRetry(
// "me" is reserved word for the authorized user of the Gmail API.
() -> this.gmail.users().messages().send("me", message).execute(),
RetriableGmailExceptionPredicate.INSTANCE);
}
static Message toGmailMessage(MimeMessage message) {
@@ -69,20 +108,18 @@ public final class GmailClient {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
message.writeTo(buffer);
byte[] rawMessageBytes = buffer.toByteArray();
String encodedEmail = Base64.encodeBase64URLSafeString(rawMessageBytes);
Message gmailMessage = new Message();
gmailMessage.setRaw(encodedEmail);
return gmailMessage;
return new Message().encodeRaw(rawMessageBytes);
} catch (MessagingException | IOException e) {
throw new EmailException(e);
}
}
static MimeMessage toMimeMessage(EmailMessage emailMessage) {
MimeMessage toMimeMessage(EmailMessage emailMessage) {
try {
MimeMessage msg =
new MimeMessage(Session.getDefaultInstance(new Properties(), /* authenticator= */ null));
msg.setFrom(emailMessage.from());
msg.setFrom(this.outgoingEmailAddressWithUsername);
msg.setReplyTo(new InternetAddress[] {replyToEmailAddress});
msg.addRecipients(
RecipientType.TO, toArray(emailMessage.recipients(), InternetAddress.class));
msg.setSubject(emailMessage.subject());
@@ -117,4 +154,41 @@ public final class GmailClient {
super(cause);
}
}
/**
* Determines if a Gmail API exception may be retried.
*
* <p>See <a href="https://developers.google.com/gmail/api/guides/handle-errors">online doc</a>
* for details.
*/
static class RetriableGmailExceptionPredicate implements Predicate<Throwable> {
static RetriableGmailExceptionPredicate INSTANCE = new RetriableGmailExceptionPredicate();
private static final int USAGE_LIMIT_EXCEEDED = 403;
private static final int TOO_MANY_REQUESTS = 429;
private static final int BACKEND_ERROR = 500;
private static final ImmutableSet<String> TRANSIENT_OVERAGE_REASONS =
ImmutableSet.of("userRateLimitExceeded", "rateLimitExceeded");
@Override
public boolean test(Throwable e) {
if (e instanceof HttpResponseException) {
return testHttpResponse((HttpResponseException) e);
}
return true;
}
private boolean testHttpResponse(HttpResponseException e) {
int statusCode = e.getStatusCode();
if (statusCode == TOO_MANY_REQUESTS || statusCode == BACKEND_ERROR) {
return true;
}
if (statusCode == USAGE_LIMIT_EXCEEDED) {
return TRANSIENT_OVERAGE_REASONS.contains(e.getStatusMessage());
}
return false;
}
}
}
@@ -17,7 +17,7 @@ package google.registry.groups;
import com.google.api.services.gmail.Gmail;
import dagger.Module;
import dagger.Provides;
import google.registry.config.CredentialModule.AdcDelegatedCredential;
import google.registry.config.CredentialModule.GmailDelegatedCredential;
import google.registry.config.RegistryConfig.Config;
import google.registry.util.GoogleCredentialsBundle;
import javax.inject.Singleton;
@@ -29,7 +29,7 @@ public class GmailModule {
@Provides
@Singleton
Gmail provideGmail(
@AdcDelegatedCredential GoogleCredentialsBundle credentialsBundle,
@GmailDelegatedCredential GoogleCredentialsBundle credentialsBundle,
@Config("projectId") String projectId) {
return new Gmail.Builder(
credentialsBundle.getHttpTransport(),
@@ -11,7 +11,7 @@
// 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.
package google.registry.model.tld;
package google.registry.model;
import static com.google.common.collect.ImmutableSortedMap.toImmutableSortedMap;
import static com.google.common.collect.Ordering.natural;
@@ -27,7 +27,6 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import google.registry.model.CreateAutoTimestamp;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.tld.Tld.TldState;
@@ -44,14 +43,13 @@ import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
/** A collection of static utility classes and functions for TLD YAML conversions. */
public class TldYamlUtils {
/** A collection of static utility classes/functions to convert entities to/from YAML files. */
public class EntityYamlUtils {
/**
* Returns an {@link ObjectMapper} object that can be used to convert a {@link Tld} object to and
* from YAML.
* Returns a new {@link ObjectMapper} object that can be used to convert an entity to/from YAML.
*/
public static ObjectMapper getObjectMapper() {
public static ObjectMapper createObjectMapper() {
SimpleModule module = new SimpleModule();
module.addSerializer(Money.class, new MoneySerializer());
module.addDeserializer(Money.class, new MoneyDeserializer());
@@ -86,6 +84,7 @@ public class TldYamlUtils {
/** A custom JSON deserializer for {@link Money}. */
public static class MoneyDeserializer extends StdDeserializer<Money> {
public MoneyDeserializer() {
this(null);
}
@@ -127,6 +126,7 @@ public class TldYamlUtils {
/** A custom JSON deserializer for {@link CurrencyUnit}. */
public static class CurrencyDeserializer extends StdDeserializer<CurrencyUnit> {
public CurrencyDeserializer() {
this(null);
}
@@ -0,0 +1,30 @@
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.model;
import com.fasterxml.jackson.databind.ObjectMapper;
import dagger.Module;
import dagger.Provides;
/** Dagger module for the entity (model) classes. */
@Module
public final class ModelModule {
/** Returns an {@link ObjectMapper} object that can be used to convert an entity to/from YAML. */
@Provides
public static ObjectMapper provideObjectMapper() {
return EntityYamlUtils.createObjectMapper();
}
}
@@ -0,0 +1,32 @@
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.model.adapters;
import google.registry.model.adapters.CurrencyUnitAdapter.UnknownCurrencyException;
import google.registry.util.StringBaseTypeAdapter;
import java.io.IOException;
import org.joda.money.CurrencyUnit;
public class CurrencyJsonAdapter extends StringBaseTypeAdapter<CurrencyUnit> {
@Override
protected CurrencyUnit fromString(String stringValue) throws IOException {
try {
return CurrencyUnitAdapter.convertFromString(stringValue);
} catch (UnknownCurrencyException e) {
throw new IOException("Unknown currency");
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,9 +22,7 @@ import org.joda.money.CurrencyUnit;
/** Adapter to use Joda {@link CurrencyUnit} when marshalling strings. */
public class CurrencyUnitAdapter extends XmlAdapter<String, CurrencyUnit> {
/** Parses a string into a {@link CurrencyUnit} object. */
@Override
public CurrencyUnit unmarshal(String currency) throws UnknownCurrencyException {
public static CurrencyUnit convertFromString(String currency) throws UnknownCurrencyException {
try {
return CurrencyUnit.of(nullToEmpty(currency).trim());
} catch (IllegalArgumentException e) {
@@ -32,10 +30,20 @@ public class CurrencyUnitAdapter extends XmlAdapter<String, CurrencyUnit> {
}
}
public static String convertFromCurrency(CurrencyUnit currency) {
return currency == null ? null : currency.toString();
}
/** Parses a string into a {@link CurrencyUnit} object. */
@Override
public CurrencyUnit unmarshal(String currency) throws UnknownCurrencyException {
return convertFromString(currency);
}
/** Converts {@link CurrencyUnit} to a string. */
@Override
public String marshal(CurrencyUnit currency) {
return currency == null ? null : currency.toString();
return convertFromCurrency(currency);
}
/** Exception to throw when failing to parse a currency. */
@@ -200,7 +200,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
.setStatusValues(domainBase.getStatusValues())
.setTransferData(domainBase.getTransferData())
.setLordnPhase(domainBase.getLordnPhase())
.setCurrentPackageToken(domainBase.getCurrentPackageToken().orElse(null));
.setCurrentBulkToken(domainBase.getCurrentBulkToken().orElse(null));
}
}
}
@@ -267,8 +267,12 @@ public class DomainBase extends EppResource
@Enumerated(EnumType.STRING)
LordnPhase lordnPhase = LordnPhase.NONE;
/** The {@link AllocationToken} for the package this domain is currently a part of. */
@Nullable VKey<AllocationToken> currentPackageToken;
/**
* The {@link AllocationToken} for the bulk pricing package this domain is currently a part of.
*/
@Nullable
@Column(name = "current_package_token")
VKey<AllocationToken> currentBulkToken;
public LordnPhase getLordnPhase() {
return lordnPhase;
@@ -302,8 +306,8 @@ public class DomainBase extends EppResource
return smdId;
}
public Optional<VKey<AllocationToken>> getCurrentPackageToken() {
return Optional.ofNullable(currentPackageToken);
public Optional<VKey<AllocationToken>> getCurrentBulkToken() {
return Optional.ofNullable(currentBulkToken);
}
/**
@@ -478,7 +482,7 @@ public class DomainBase extends EppResource
// events.
.setAutorenewBillingEvent(transferData.getServerApproveAutorenewEvent())
.setAutorenewPollMessage(transferData.getServerApproveAutorenewPollMessage())
.setCurrentPackageToken(null);
.setCurrentBulkToken(null);
if (transferData.getTransferPeriod().getValue() == 1) {
// Set the grace period using a key to the pre-scheduled transfer billing event. Not using
// GracePeriod.forBillingEvent() here in order to avoid the actual fetch.
@@ -910,23 +914,22 @@ public class DomainBase extends EppResource
return thisCastToDerived();
}
public B setCurrentPackageToken(@Nullable VKey<AllocationToken> currentPackageToken) {
if (currentPackageToken == null) {
getInstance().currentPackageToken = currentPackageToken;
public B setCurrentBulkToken(@Nullable VKey<AllocationToken> currentBulkToken) {
if (currentBulkToken == null) {
getInstance().currentBulkToken = currentBulkToken;
return thisCastToDerived();
}
AllocationToken token =
tm().transact(() -> tm().loadByKeyIfPresent(currentPackageToken))
tm().transact(() -> tm().loadByKeyIfPresent(currentBulkToken))
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"The package token %s does not exist",
currentPackageToken.getKey())));
"The bulk token %s does not exist", currentBulkToken.getKey())));
checkArgument(
token.getTokenType().equals(TokenType.PACKAGE),
"The currentPackageToken must have a PACKAGE TokenType");
getInstance().currentPackageToken = currentPackageToken;
token.getTokenType().equals(TokenType.BULK_PRICING),
"The currentBulkToken must have a BULK_PRICING TokenType");
getInstance().currentBulkToken = currentBulkToken;
return thisCastToDerived();
}
}
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.model.domain.packagetoken;
package google.registry.model.domain.bulktoken;
import google.registry.model.ImmutableObject;
import google.registry.model.eppinput.EppInput.CommandExtension;
import javax.xml.bind.annotation.XmlRootElement;
/** A package token extension that may be present on EPP domain commands. */
/** A bulk token extension that may be present on EPP domain commands. */
@XmlRootElement(name = "info")
public class PackageTokenExtension extends ImmutableObject implements CommandExtension {}
public class BulkTokenExtension extends ImmutableObject implements CommandExtension {}
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.model.domain.packagetoken;
package google.registry.model.domain.bulktoken;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.token.AllocationToken;
@@ -24,18 +24,18 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
* An XML data object that represents a package token extension that may be present on the response
* to EPP domain info commands.
* An XML data object that represents a bulk token extension that may be present on the response to
* EPP domain info commands.
*/
@XmlRootElement(name = "packageData")
public class PackageTokenResponseExtension extends ImmutableObject implements ResponseExtension {
@XmlRootElement(name = "bulkData")
public class BulkTokenResponseExtension extends ImmutableObject implements ResponseExtension {
/** Token string of the PACKAGE token the name belongs to. */
@XmlJavaTypeAdapter(TrimWhitespaceAdapter.class)
String token;
public static PackageTokenResponseExtension create(Optional<VKey<AllocationToken>> tokenKey) {
PackageTokenResponseExtension instance = new PackageTokenResponseExtension();
public static BulkTokenResponseExtension create(Optional<VKey<AllocationToken>> tokenKey) {
BulkTokenResponseExtension instance = new BulkTokenResponseExtension();
instance.token = "";
if (tokenKey.isPresent()) {
instance.token = tokenKey.get().getKey().toString();
@@ -13,12 +13,11 @@
// limitations under the License.
@XmlSchema(
namespace = "urn:google:params:xml:ns:packageToken-1.0",
xmlns =
@XmlNs(prefix = "packageToken", namespaceURI = "urn:google:params:xml:ns:packageToken-1.0"),
namespace = "urn:google:params:xml:ns:bulkToken-1.0",
xmlns = @XmlNs(prefix = "bulkToken", namespaceURI = "urn:google:params:xml:ns:bulkToken-1.0"),
elementFormDefault = XmlNsForm.QUALIFIED)
@XmlAccessorType(XmlAccessType.FIELD)
package google.registry.model.domain.packagetoken;
package google.registry.model.domain.bulktoken;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -77,10 +77,10 @@ import org.joda.time.DateTime;
public class AllocationToken extends UpdateAutoTimestampEntity implements Buildable {
private static final long serialVersionUID = -3954475393220876903L;
private static final String REMOVE_PACKAGE = "__REMOVEPACKAGE__";
private static final String REMOVE_DOMAIN = "__REMOVEDOMAIN__";
private static final ImmutableMap<String, TokenBehavior> STATIC_TOKEN_BEHAVIORS =
ImmutableMap.of(REMOVE_PACKAGE, TokenBehavior.REMOVE_PACKAGE);
ImmutableMap.of(REMOVE_DOMAIN, TokenBehavior.REMOVE_DOMAIN);
// Promotions should only move forward, and ENDED / CANCELLED are terminal states.
private static final ImmutableMultimap<TokenStatus, TokenStatus> VALID_TOKEN_STATUS_TRANSITIONS =
@@ -91,10 +91,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
private static final ImmutableMap<String, AllocationToken> BEHAVIORAL_TOKENS =
ImmutableMap.of(
REMOVE_PACKAGE,
REMOVE_DOMAIN,
new AllocationToken.Builder()
.setTokenType(TokenType.UNLIMITED_USE)
.setToken(REMOVE_PACKAGE)
.setToken(REMOVE_DOMAIN)
.build());
public static Optional<AllocationToken> maybeGetStaticTokenInstance(String name) {
@@ -119,9 +119,14 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
/** Type of the token that indicates how and where it should be used. */
public enum TokenType {
/** Token used for bulk pricing */
BULK_PRICING,
/** Token saved on a TLD to use if no other token is passed from the client */
DEFAULT_PROMO,
/** Token used for package pricing */
/** This is the old name for what is now BULK_PRICING. */
// TODO(sarahbot@): Remove this type once all tokens of this type have been scrubbed from the
// database
@Deprecated
PACKAGE,
/** Invalid after use */
SINGLE_USE,
@@ -137,10 +142,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
/** No special behavior */
DEFAULT,
/**
* REMOVE_PACKAGE triggers domain removal from promotional package, bypasses DEFAULT token
* REMOVE_DOMAIN triggers domain removal from a bulk pricing package, bypasses DEFAULT token
* validations.
*/
REMOVE_PACKAGE
REMOVE_DOMAIN
}
/** The status of this token with regard to any potential promotion. */
@@ -344,12 +349,13 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
checkArgumentNotNull(getInstance().tokenType, "Token type must be specified");
checkArgument(!Strings.isNullOrEmpty(getInstance().token), "Token must not be null or empty");
checkArgument(
!getInstance().tokenType.equals(TokenType.PACKAGE)
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED),
"Package tokens must have renewalPriceBehavior set to SPECIFIED");
"Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
checkArgument(
!getInstance().tokenType.equals(TokenType.PACKAGE) || !getInstance().discountPremiums,
"Package tokens cannot discount premium names");
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| !getInstance().discountPremiums,
"Bulk tokens cannot discount premium names");
checkArgument(
getInstance().domainName == null || TokenType.SINGLE_USE.equals(getInstance().tokenType),
"Domain name can only be specified for SINGLE_USE tokens");
@@ -358,10 +364,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
|| TokenType.SINGLE_USE.equals(getInstance().tokenType),
"Redemption history entry can only be specified for SINGLE_USE tokens");
checkArgument(
getInstance().tokenType != TokenType.PACKAGE
getInstance().tokenType != TokenType.BULK_PRICING
|| (getInstance().allowedClientIds != null
&& getInstance().allowedClientIds.size() == 1),
"PACKAGE tokens must have exactly one allowed client registrar");
"BULK_PRICING tokens must have exactly one allowed client registrar");
checkArgument(
getInstance().discountFraction > 0 || !getInstance().discountPremiums,
"Discount premiums can only be specified along with a discount fraction");
@@ -36,46 +36,53 @@ import org.hibernate.annotations.Type;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** An entity representing a package promotion. */
@Entity
/**
* An entity representing a bulk pricing promotion. Note that this table is still called
* PackagePromotion in Cloud SQL.
*/
@Entity(name = "PackagePromotion")
@javax.persistence.Table(indexes = {@javax.persistence.Index(columnList = "token")})
public class PackagePromotion extends ImmutableObject implements Buildable {
public class BulkPricingPackage extends ImmutableObject implements Buildable {
/** An autogenerated identifier for the package promotion. */
/** An autogenerated identifier for the bulk pricing promotion. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long packagePromotionId;
@Column(name = "package_promotion_id")
long bulkPricingId;
/** The allocation token string for the package. */
/** The allocation token string for the bulk pricing package. */
@Column(nullable = false)
VKey<AllocationToken> token;
/** The maximum number of active domains the package allows at any given time. */
/** The maximum number of active domains the bulk pricing package allows at any given time. */
@Column(nullable = false)
int maxDomains;
/** The maximum number of domains that can be created in the package each year. */
/** The maximum number of domains that can be created in the bulk pricing package each year. */
@Column(nullable = false)
int maxCreates;
/** The annual price of the package. */
/** The annual price of the bulk pricing package. */
@Type(type = JodaMoneyType.TYPE_NAME)
@Columns(
columns = {
@Column(name = "package_price_amount", nullable = false),
@Column(name = "package_price_currency", nullable = false)
})
Money packagePrice;
Money bulkPrice;
/** The next billing date of the package. */
/** The next billing date of the bulk pricing package. */
@Column(nullable = false)
DateTime nextBillingDate = END_OF_TIME;
/** Date the last warning email was sent that the package has exceeded the maxDomains limit. */
/**
* Date the last warning email was sent that the bulk pricing package has exceeded the maxDomains
* limit.
*/
@Nullable DateTime lastNotificationSent;
public long getId() {
return packagePromotionId;
return bulkPricingId;
}
public VKey<AllocationToken> getToken() {
@@ -90,8 +97,8 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return maxCreates;
}
public Money getPackagePrice() {
return packagePrice;
public Money getBulkPrice() {
return bulkPrice;
}
public DateTime getNextBillingDate() {
@@ -102,18 +109,18 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return Optional.ofNullable(lastNotificationSent);
}
/** Loads and returns a PackagePromotion entity by its token string directly from Cloud SQL. */
public static Optional<PackagePromotion> loadByTokenString(String tokenString) {
/** Loads and returns a BulkPricingPackage entity by its token string directly from Cloud SQL. */
public static Optional<BulkPricingPackage> loadByTokenString(String tokenString) {
tm().assertInTransaction();
return tm().query("FROM PackagePromotion WHERE token = :token", PackagePromotion.class)
return tm().query("FROM PackagePromotion WHERE token = :token", BulkPricingPackage.class)
.setParameter("token", VKey.create(AllocationToken.class, tokenString))
.getResultStream()
.findFirst();
}
@Override
public VKey<PackagePromotion> createVKey() {
return VKey.create(PackagePromotion.class, packagePromotionId);
public VKey<BulkPricingPackage> createVKey() {
return VKey.create(BulkPricingPackage.class, bulkPricingId);
}
@Override
@@ -121,28 +128,29 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return new Builder(clone(this));
}
/** A builder for constructing {@link PackagePromotion} objects, since they are immutable. */
public static class Builder extends Buildable.Builder<PackagePromotion> {
/** A builder for constructing {@link BulkPricingPackage} objects, since they are immutable. */
public static class Builder extends Buildable.Builder<BulkPricingPackage> {
public Builder() {}
private Builder(PackagePromotion instance) {
private Builder(BulkPricingPackage instance) {
super(instance);
}
@Override
public PackagePromotion build() {
public BulkPricingPackage build() {
checkArgumentNotNull(getInstance().token, "Allocation token must be specified");
AllocationToken allocationToken = tm().transact(() -> tm().loadByKey(getInstance().token));
checkArgument(
allocationToken.tokenType == TokenType.PACKAGE,
"Allocation token must be a PACKAGE type");
allocationToken.tokenType == TokenType.BULK_PRICING,
"Allocation token must be a BULK_PRICING type");
return super.build();
}
public Builder setToken(AllocationToken token) {
checkArgumentNotNull(token, "Allocation token must not be null");
checkArgument(
token.tokenType == TokenType.PACKAGE, "Allocation token must be a PACKAGE type");
token.tokenType == TokenType.BULK_PRICING,
"Allocation token must be a BULK_PRICING type");
getInstance().token = token.createVKey();
return this;
}
@@ -159,9 +167,9 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return this;
}
public Builder setPackagePrice(Money packagePrice) {
checkArgumentNotNull(packagePrice, "Package price must not be null");
getInstance().packagePrice = packagePrice;
public Builder setBulkPrice(Money bulkPrice) {
checkArgumentNotNull(bulkPrice, "Bulk price must not be null");
getInstance().bulkPrice = bulkPrice;
return this;
}
@@ -20,11 +20,13 @@ import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.Expose;
import google.registry.model.Buildable;
import google.registry.model.ImmutableObject;
import google.registry.model.JsonMapBuilder;
import google.registry.model.Jsonifiable;
import google.registry.model.UnsafeSerializable;
import google.registry.tools.GsonUtils.GsonPostProcessable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -54,7 +56,8 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlTransient
@Embeddable
@MappedSuperclass
public class Address extends ImmutableObject implements Jsonifiable, UnsafeSerializable {
public class Address extends ImmutableObject
implements Jsonifiable, UnsafeSerializable, GsonPostProcessable {
/**
* At most three lines of addresses parsed from XML elements.
@@ -87,6 +90,7 @@ public class Address extends ImmutableObject implements Jsonifiable, UnsafeSeria
*/
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
@Transient
@Expose
protected List<String> street;
@XmlTransient @IgnoredInDiffableMap protected String streetLine1;
@@ -96,18 +100,22 @@ public class Address extends ImmutableObject implements Jsonifiable, UnsafeSeria
@XmlTransient @IgnoredInDiffableMap protected String streetLine3;
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
@Expose
protected String city;
@XmlElement(name = "sp")
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
@Expose
protected String state;
@XmlElement(name = "pc")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@Expose
protected String zip;
@XmlElement(name = "cc")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@Expose
protected String countryCode;
public ImmutableList<String> getStreet() {
@@ -146,6 +154,16 @@ public class Address extends ImmutableObject implements Jsonifiable, UnsafeSeria
return new Builder<>(clone(this));
}
@Override
public void postProcess() {
if (street == null || street.isEmpty()) {
return;
}
streetLine1 = street.get(0);
streetLine2 = street.size() >= 2 ? street.get(1) : null;
streetLine3 = street.size() >= 3 ? street.get(2) : null;
}
/** A builder for constructing {@link Address}. */
public static class Builder<T extends Address> extends Buildable.Builder<T> {
@@ -222,11 +240,6 @@ public class Address extends ImmutableObject implements Jsonifiable, UnsafeSeria
*/
@SuppressWarnings("unused")
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
if (street == null || street.isEmpty()) {
return;
}
streetLine1 = street.get(0);
streetLine2 = street.size() >= 2 ? street.get(1) : null;
streetLine3 = street.size() >= 3 ? street.get(2) : null;
postProcess();
}
}
@@ -51,7 +51,7 @@ public class EppXmlTransformer {
"allocate.xsd",
"superuser.xsd",
"allocationToken-1.0.xsd",
"packageToken.xsd");
"bulkToken.xsd");
private static final XmlTransformer INPUT_TRANSFORMER =
new XmlTransformer(SCHEMAS, EppInput.class);
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactCommand;
import google.registry.model.domain.DomainCommand;
import google.registry.model.domain.bulktoken.BulkTokenExtension;
import google.registry.model.domain.fee06.FeeCheckCommandExtensionV06;
import google.registry.model.domain.fee06.FeeCreateCommandExtensionV06;
import google.registry.model.domain.fee06.FeeInfoCommandExtensionV06;
@@ -45,7 +46,6 @@ import google.registry.model.domain.launch.LaunchDeleteExtension;
import google.registry.model.domain.launch.LaunchInfoExtension;
import google.registry.model.domain.launch.LaunchUpdateExtension;
import google.registry.model.domain.metadata.MetadataExtension;
import google.registry.model.domain.packagetoken.PackageTokenExtension;
import google.registry.model.domain.rgp.RgpUpdateExtension;
import google.registry.model.domain.secdns.SecDnsCreateExtension;
import google.registry.model.domain.secdns.SecDnsUpdateExtension;
@@ -362,8 +362,8 @@ public class EppInput extends ImmutableObject {
// Other extensions
@XmlElementRef(type = AllocationTokenExtension.class),
@XmlElementRef(type = BulkTokenExtension.class),
@XmlElementRef(type = MetadataExtension.class),
@XmlElementRef(type = PackageTokenExtension.class),
@XmlElementRef(type = RgpUpdateExtension.class),
@XmlElementRef(type = SecDnsCreateExtension.class),
@XmlElementRef(type = SecDnsUpdateExtension.class)
@@ -23,6 +23,7 @@ import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactInfoData;
import google.registry.model.domain.DomainInfoData;
import google.registry.model.domain.DomainRenewData;
import google.registry.model.domain.bulktoken.BulkTokenResponseExtension;
import google.registry.model.domain.fee06.FeeCheckResponseExtensionV06;
import google.registry.model.domain.fee06.FeeCreateResponseExtensionV06;
import google.registry.model.domain.fee06.FeeDeleteResponseExtensionV06;
@@ -43,7 +44,6 @@ import google.registry.model.domain.fee12.FeeRenewResponseExtensionV12;
import google.registry.model.domain.fee12.FeeTransferResponseExtensionV12;
import google.registry.model.domain.fee12.FeeUpdateResponseExtensionV12;
import google.registry.model.domain.launch.LaunchCheckResponseExtension;
import google.registry.model.domain.packagetoken.PackageTokenResponseExtension;
import google.registry.model.domain.rgp.RgpInfoExtension;
import google.registry.model.domain.secdns.SecDnsInfoExtension;
import google.registry.model.eppcommon.Trid;
@@ -122,6 +122,7 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
/** Zero or more response extensions. */
@XmlElementRefs({
@XmlElementRef(type = BulkTokenResponseExtension.class),
@XmlElementRef(type = FeeCheckResponseExtensionV06.class),
@XmlElementRef(type = FeeInfoResponseExtensionV06.class),
@XmlElementRef(type = FeeCreateResponseExtensionV06.class),
@@ -142,7 +143,6 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
@XmlElementRef(type = FeeTransferResponseExtensionV12.class),
@XmlElementRef(type = FeeUpdateResponseExtensionV12.class),
@XmlElementRef(type = LaunchCheckResponseExtension.class),
@XmlElementRef(type = PackageTokenResponseExtension.class),
@XmlElementRef(type = RgpInfoExtension.class),
@XmlElementRef(type = SecDnsInfoExtension.class)
})
@@ -211,6 +211,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
*/
@Id
@Column(nullable = false)
@Expose
String registrarId;
/**
@@ -224,6 +225,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
* @see <a href="http://www.icann.org/registrar-reports/accredited-list.html">ICANN-Accredited
* Registrars</a>
*/
@Expose
@Column(nullable = false)
String registrarName;
@@ -237,10 +239,10 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
State state;
/** The set of TLDs which this registrar is allowed to access. */
Set<String> allowedTlds;
@Expose Set<String> allowedTlds;
/** Host name of WHOIS server. */
String whoisServer;
@Expose String whoisServer;
/** Base URLs for the registrar's RDAP servers. */
Set<String> rdapBaseUrls;
@@ -287,6 +289,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
* unrestricted UTF-8.
*/
@Embedded
@Expose
@AttributeOverrides({
@AttributeOverride(
name = "streetLine1",
@@ -323,13 +326,13 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
RegistrarAddress internationalizedAddress;
/** Voice number. */
String phoneNumber;
@Expose String phoneNumber;
/** Fax number. */
String faxNumber;
@Expose String faxNumber;
/** Email address. */
String emailAddress;
@Expose String emailAddress;
// External IDs.
@@ -345,7 +348,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
* @see <a href="http://www.iana.org/assignments/registrar-ids/registrar-ids.txt">Registrar
* IDs</a>
*/
@Nullable Long ianaIdentifier;
@Expose @Nullable Long ianaIdentifier;
/** Purchase Order number used for invoices in external billing system, if applicable. */
@Nullable String poNumber;
@@ -358,10 +361,10 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
* accessed by {@link #getBillingAccountMap}, a sorted map is returned to guarantee deterministic
* behavior when serializing the map, for display purpose for instance.
*/
@Nullable Map<CurrencyUnit, String> billingAccountMap;
@Expose @Nullable Map<CurrencyUnit, String> billingAccountMap;
/** URL of registrar's website. */
String url;
@Expose String url;
/**
* ICANN referral email address.
@@ -369,10 +372,10 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
* <p>This value is specified in the initial registrar contact. It can't be edited in the web GUI,
* and it must be specified when the registrar account is created.
*/
String icannReferralEmail;
@Expose String icannReferralEmail;
/** Id of the folder in drive used to publish information for this registrar. */
String driveFolderId;
@Expose String driveFolderId;
// Metadata.
@@ -400,7 +403,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
boolean contactsRequireSyncing = true;
/** Whether or not registry lock is allowed for this registrar. */
boolean registryLockAllowed = false;
@Expose boolean registryLockAllowed = false;
public String getRegistrarId() {
return registrarId;
@@ -45,6 +45,15 @@ import com.google.common.net.InternetDomainName;
import google.registry.model.Buildable;
import google.registry.model.CacheUtils;
import google.registry.model.CreateAutoTimestamp;
import google.registry.model.EntityYamlUtils.CreateAutoTimestampDeserializer;
import google.registry.model.EntityYamlUtils.CurrencyDeserializer;
import google.registry.model.EntityYamlUtils.CurrencySerializer;
import google.registry.model.EntityYamlUtils.OptionalDurationSerializer;
import google.registry.model.EntityYamlUtils.OptionalStringSerializer;
import google.registry.model.EntityYamlUtils.TimedTransitionPropertyMoneyDeserializer;
import google.registry.model.EntityYamlUtils.TimedTransitionPropertyTldStateDeserializer;
import google.registry.model.EntityYamlUtils.TokenVKeyListDeserializer;
import google.registry.model.EntityYamlUtils.TokenVKeyListSerializer;
import google.registry.model.ImmutableObject;
import google.registry.model.UnsafeSerializable;
import google.registry.model.common.TimedTransitionProperty;
@@ -52,15 +61,6 @@ import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.tld.TldYamlUtils.CreateAutoTimestampDeserializer;
import google.registry.model.tld.TldYamlUtils.CurrencyDeserializer;
import google.registry.model.tld.TldYamlUtils.CurrencySerializer;
import google.registry.model.tld.TldYamlUtils.OptionalDurationSerializer;
import google.registry.model.tld.TldYamlUtils.OptionalStringSerializer;
import google.registry.model.tld.TldYamlUtils.TimedTransitionPropertyMoneyDeserializer;
import google.registry.model.tld.TldYamlUtils.TimedTransitionPropertyTldStateDeserializer;
import google.registry.model.tld.TldYamlUtils.TokenVKeyListDeserializer;
import google.registry.model.tld.TldYamlUtils.TokenVKeyListSerializer;
import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.ReservedList;
import google.registry.persistence.VKey;
@@ -29,6 +29,7 @@ import google.registry.ui.server.console.ConsoleDomainGetAction;
import google.registry.ui.server.console.RegistrarsAction;
import google.registry.ui.server.console.settings.ContactAction;
import google.registry.ui.server.console.settings.SecurityAction;
import google.registry.ui.server.console.settings.WhoisRegistrarFieldsAction;
import google.registry.ui.server.registrar.ConsoleOteSetupAction;
import google.registry.ui.server.registrar.ConsoleRegistrarCreatorAction;
import google.registry.ui.server.registrar.ConsoleUiAction;
@@ -73,6 +74,8 @@ interface FrontendRequestComponent {
SecurityAction securityAction();
WhoisRegistrarFieldsAction whoisRegistrarFieldsAction();
@Subcomponent.Builder
abstract class Builder implements RequestComponentBuilder<FrontendRequestComponent> {
@Override public abstract Builder requestModule(RequestModule requestModule);
@@ -0,0 +1,33 @@
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.persistence;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates which {@link TransactionIsolationLevel} that a {@link
* google.registry.flows.TransactionalFlow} show run at.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface IsolationLevel {
TransactionIsolationLevel value();
}
@@ -27,9 +27,9 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.flogger.FluentLogger;
import dagger.BindsOptionalOf;
import dagger.Module;
import dagger.Provides;
@@ -65,7 +65,6 @@ import org.hibernate.cfg.Environment;
/** Dagger module class for the persistence layer. */
@Module
public abstract class PersistenceModule {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
// This name must be the same as the one defined in persistence.xml.
public static final String PERSISTENCE_UNIT_NAME = "nomulus";
@@ -166,12 +165,10 @@ public abstract class PersistenceModule {
// Override the default minimum which is tuned for the Registry server. A worker VM should
// release all connections if it no longer interacts with the database.
overrides.put(HIKARI_MINIMUM_IDLE, "0");
/**
* Disable Hikari's maxPoolSize limit check by setting it to an absurdly large number. The
* effective (and desirable) limit is the number of pipeline threads on the pipeline worker,
* which can be configured using pipeline options. See {@link RegistryPipelineOptions} for more
* information.
*/
// Disable Hikari's maxPoolSize limit check by setting it to an absurdly large number. The
// effective (and desirable) limit is the number of pipeline threads on the pipeline worker,
// which can be configured using pipeline options. See {@link RegistryPipelineOptions} for more
// information.
overrides.put(HIKARI_MAXIMUM_POOL_SIZE, String.valueOf(Integer.MAX_VALUE));
instanceConnectionNameOverride
.map(Provider::get)
@@ -303,7 +300,7 @@ public abstract class PersistenceModule {
private static EntityManagerFactory create(Map<String, String> properties) {
// If there are no annotated classes, we can create the EntityManagerFactory from the generic
// method. Otherwise we have to use a more tailored approach. Note that this adds to the set
// method. Otherwise, we have to use a more tailored approach. Note that this adds to the set
// of annotated classes defined in the configuration, it does not override them.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(
@@ -322,8 +319,7 @@ public abstract class PersistenceModule {
overrides.put(Environment.USER, credential.login());
overrides.put(Environment.PASS, credential.password());
} catch (Throwable e) {
// TODO(b/184631990): after SQL becomes primary, throw an exception to fail fast
logger.atSevere().withCause(e).log("Failed to get SQL credential from Secret Manager.");
throw new RuntimeException("Failed to get SQL credential from Secret Manager.", e);
}
}
@@ -340,11 +336,13 @@ public abstract class PersistenceModule {
TRANSACTION_SERIALIZABLE;
private final int value;
private final String mode;
TransactionIsolationLevel() {
try {
// name() is final in parent class (Enum.java), therefore safe to call in constructor.
value = Connection.class.getField(name()).getInt(null);
mode = name().substring(12).replace('_', ' ');
} catch (Exception e) {
throw new IllegalStateException(
String.format(
@@ -356,6 +354,14 @@ public abstract class PersistenceModule {
public final int getValue() {
return value;
}
public final String getMode() {
return mode;
}
public static TransactionIsolationLevel fromMode(String mode) {
return valueOf(String.format("TRANSACTION_%s", Ascii.toUpperCase(mode.replace(' ', '_'))));
}
}
/** Types of {@link JpaTransactionManager JpaTransactionManagers}. */
@@ -14,6 +14,7 @@
package google.registry.persistence.transaction;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import google.registry.persistence.VKey;
import java.util.function.Supplier;
import javax.persistence.EntityManager;
@@ -31,21 +32,6 @@ public interface JpaTransactionManager extends TransactionManager {
*/
EntityManager getStandaloneEntityManager();
/**
* Specifies a database snapshot exported by another transaction to use in the current
* transaction.
*
* <p>This is a Postgresql-specific feature. This method must be called before any other SQL
* commands in a transaction.
*
* <p>To support large queries, transaction isolation level is fixed at the REPEATABLE_READ to
* avoid exhausting predicate locks at the SERIALIZABLE level.
*
* @see google.registry.beam.common.DatabaseSnapshot
*/
// TODO(b/193662898): vendor-independent support for richer transaction semantics.
JpaTransactionManager setDatabaseSnapshot(String snapshotId);
/**
* Returns the {@link EntityManager} for the current request.
*
@@ -56,8 +42,8 @@ public interface JpaTransactionManager extends TransactionManager {
/**
* Creates a JPA SQL query for the given query string and result class.
*
* <p>This is a convenience method for the longer <code>
* jpaTm().getEntityManager().createQuery(...)</code>.
* <p>This is a convenience method for the longer {@code
* jpaTm().getEntityManager().createQuery(...)}.
*/
<T> TypedQuery<T> query(String sqlString, Class<T> resultClass);
@@ -67,8 +53,8 @@ public interface JpaTransactionManager extends TransactionManager {
/**
* Creates a JPA SQL query for the given query string.
*
* <p>This is a convenience method for the longer <code>
* jpaTm().getEntityManager().createQuery(...)</code>.
* <p>This is a convenience method for the longer {@code
* jpaTm().getEntityManager().createQuery(...)}.
*
* <p>Note that while this method can legally be used for queries that return results, <u>it
* should not be</u>, as it does not correctly detach entities as must be done for nomulus model
@@ -79,9 +65,21 @@ public interface JpaTransactionManager extends TransactionManager {
/** Executes the work in a transaction with no retries and returns the result. */
<T> T transactNoRetry(Supplier<T> work);
/**
* Executes the work in a transaction at the given {@link TransactionIsolationLevel} with no
* retries and returns the result.
*/
<T> T transactNoRetry(Supplier<T> work, TransactionIsolationLevel isolationLevel);
/** Executes the work in a transaction with no retries. */
void transactNoRetry(Runnable work);
/**
* Executes the work in a transaction at the given {@link TransactionIsolationLevel} with no
* retries.
*/
void transactNoRetry(Runnable work, TransactionIsolationLevel isolationLevel);
/** Deletes the entity by its id, throws exception if the entity is not deleted. */
<T> void assertDelete(VKey<T> key);
@@ -99,4 +97,13 @@ public interface JpaTransactionManager extends TransactionManager {
static Query setQueryFetchSize(Query query, int fetchSize) {
return query.setHint("org.hibernate.fetchSize", fetchSize);
}
/** Return the default {@link TransactionIsolationLevel} specified via the config file. */
TransactionIsolationLevel getDefaultTransactionIsolationLevel();
/** Return the {@link TransactionIsolationLevel} used in the current transaction. */
TransactionIsolationLevel getCurrentTransactionIsolationLevel();
/** Asserts that the current transaction runs at the given level. */
void assertTransactionIsolationLevel(TransactionIsolationLevel expectedLevel);
}
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.config.RegistryConfig.getHibernatePerTransactionIsolationEnabled;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static java.util.AbstractMap.SimpleEntry;
import static java.util.stream.Collectors.joining;
@@ -31,6 +32,7 @@ import com.google.common.collect.Streams;
import com.google.common.flogger.FluentLogger;
import google.registry.model.ImmutableObject;
import google.registry.persistence.JpaRetries;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import google.registry.persistence.VKey;
import google.registry.util.Clock;
import google.registry.util.Retrier;
@@ -65,6 +67,7 @@ import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.metamodel.EntityType;
import org.hibernate.cfg.Environment;
import org.joda.time.DateTime;
/** Implementation of {@link JpaTransactionManager} for JPA compatible database. */
@@ -77,9 +80,6 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
private final EntityManagerFactory emf;
private final Clock clock;
// TODO(b/177588434): Investigate alternatives for managing transaction information. ThreadLocal
// adds an unnecessary restriction that each request has to be processed by one thread
// synchronously.
private static final ThreadLocal<TransactionInfo> transactionInfo =
ThreadLocal.withInitial(TransactionInfo::new);
@@ -109,22 +109,6 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
return entityManager;
}
@Override
public JpaTransactionManager setDatabaseSnapshot(String snapshotId) {
// Postgresql-specific: 'set transaction' command must be called inside a transaction
assertInTransaction();
EntityManager entityManager = getEntityManager();
// Isolation is hardcoded to REPEATABLE READ, as specified by parent's Javadoc.
entityManager
.createNativeQuery("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ")
.executeUpdate();
entityManager
.createNativeQuery(String.format("SET TRANSACTION SNAPSHOT '%s'", snapshotId))
.executeUpdate();
return this;
}
@Override
public <T> TypedQuery<T> query(String sqlString, Class<T> resultClass) {
return new DetachingTypedQuery<>(getEntityManager().createQuery(sqlString, resultClass));
@@ -153,18 +137,42 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public <T> T transact(Supplier<T> work) {
// This prevents inner transaction from retrying, thus avoiding a cascade retry effect.
if (inTransaction()) {
return transactNoRetry(work);
public void assertTransactionIsolationLevel(TransactionIsolationLevel expectedLevel) {
assertInTransaction();
TransactionIsolationLevel currentLevel = getCurrentTransactionIsolationLevel();
if (currentLevel != expectedLevel) {
throw new IllegalStateException(
String.format(
"Current transaction isolation level (%s) is not as expected (%s)",
currentLevel, expectedLevel));
}
return retrier.callWithRetry(() -> transactNoRetry(work), JpaRetries::isFailedTxnRetriable);
}
@Override
public <T> T transactNoRetry(Supplier<T> work) {
public <T> T transact(Supplier<T> work, TransactionIsolationLevel isolationLevel) {
// This prevents inner transaction from retrying, thus avoiding a cascade retry effect.
if (inTransaction()) {
return work.get();
return transactNoRetry(work, isolationLevel);
}
return retrier.callWithRetry(
() -> transactNoRetry(work, isolationLevel), JpaRetries::isFailedTxnRetriable);
}
@Override
public <T> T transact(Supplier<T> work) {
return transact(work, null);
}
@Override
public <T> T transactNoRetry(
Supplier<T> work, @Nullable TransactionIsolationLevel isolationLevel) {
if (inTransaction()) {
if (getHibernatePerTransactionIsolationEnabled()) {
throw new IllegalStateException("Nested transaction detected");
} else {
logger.atWarning().log("Nested transaction detected");
return work.get();
}
}
TransactionInfo txnInfo = transactionInfo.get();
txnInfo.entityManager = emf.createEntityManager();
@@ -172,6 +180,18 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
try {
txn.begin();
txnInfo.start(clock);
if (isolationLevel != null) {
if (getHibernatePerTransactionIsolationEnabled()) {
getEntityManager()
.createNativeQuery(
String.format("SET TRANSACTION ISOLATION LEVEL %s", isolationLevel.getMode()))
.executeUpdate();
logger.atInfo().log("Running transaction at %s", isolationLevel);
} else {
logger.atWarning().log(
"Per-transaction isolation level disabled, but %s was requested", isolationLevel);
}
}
T result = work.get();
txn.commit();
return result;
@@ -190,21 +210,55 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void transact(Runnable work) {
public <T> T transactNoRetry(Supplier<T> work) {
return transactNoRetry(work, null);
}
@Override
public void transact(Runnable work, TransactionIsolationLevel isolationLevel) {
transact(
() -> {
work.run();
return null;
});
},
isolationLevel);
}
@Override
public void transactNoRetry(Runnable work) {
public void transact(Runnable work) {
transact(work, null);
}
@Override
public void transactNoRetry(Runnable work, TransactionIsolationLevel isolationLevel) {
transactNoRetry(
() -> {
work.run();
return null;
});
},
isolationLevel);
}
@Override
public void transactNoRetry(Runnable work) {
transactNoRetry(work, null);
}
@Override
public TransactionIsolationLevel getDefaultTransactionIsolationLevel() {
return TransactionIsolationLevel.valueOf(
(String) emf.getProperties().get(Environment.ISOLATION));
}
@Override
public TransactionIsolationLevel getCurrentTransactionIsolationLevel() {
assertInTransaction();
String mode =
(String)
getEntityManager()
.createNativeQuery("SHOW TRANSACTION ISOLATION LEVEL")
.getSingleResult();
return TransactionIsolationLevel.fromMode(mode);
}
@Override
@@ -303,7 +357,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
Integer.class)
.setMaxResults(1);
entityIds.forEach(entityId -> query.setParameter(entityId.name, entityId.value));
return query.getResultList().size() > 0;
return !query.getResultList().isEmpty();
}
@Override
@@ -522,7 +576,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
.collect(toImmutableSet());
}
private String getAndClause(ImmutableSet<EntityId> entityIds) {
private static String getAndClause(ImmutableSet<EntityId> entityIds) {
return entityIds.stream()
.map(entityId -> String.format("%s = :%s", entityId.name, entityId.name))
.collect(joining(" AND "));
@@ -572,7 +626,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
try {
getEntityManager().getMetamodel().entity(object.getClass());
} catch (IllegalArgumentException e) {
// The object is not an entity. Return without detaching.
// The object is not an entity. Return without detaching.
return object;
}
@@ -653,7 +707,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
TypedQuery<T> delegate;
public DetachingTypedQuery(TypedQuery<T> delegate) {
DetachingTypedQuery(TypedQuery<T> delegate) {
this.delegate = delegate;
}
@@ -882,7 +936,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
@Override
public Optional<T> first() {
List<T> results = buildQuery().setMaxResults(1).getResultList();
return results.size() > 0 ? Optional.of(detach(results.get(0))) : Optional.empty();
return !results.isEmpty() ? Optional.of(detach(results.get(0))) : Optional.empty();
}
@Override
@@ -911,7 +965,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
public ImmutableList<T> list() {
return buildQuery().getResultList().stream()
.map(JpaTransactionManagerImpl.this::detach)
.collect(ImmutableList.toImmutableList());
.collect(toImmutableList());
}
}
}
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import google.registry.persistence.VKey;
import java.util.NoSuchElementException;
import java.util.Optional;
@@ -49,9 +50,18 @@ public interface TransactionManager {
/** Executes the work in a transaction and returns the result. */
<T> T transact(Supplier<T> work);
/**
* Executes the work in a transaction at the given {@link TransactionIsolationLevel} and returns
* the result.
*/
<T> T transact(Supplier<T> work, TransactionIsolationLevel isolationLevel);
/** Executes the work in a transaction. */
void transact(Runnable work);
/** Executes the work in a transaction at the given {@link TransactionIsolationLevel}. */
void transact(Runnable work, TransactionIsolationLevel isolationLevel);
/** Returns the time associated with the start of this particular transaction attempt. */
DateTime getTransactionTime();
@@ -17,9 +17,9 @@ package google.registry.reporting.billing;
import static google.registry.reporting.ReportingModule.PARAM_YEAR_MONTH;
import static google.registry.request.Action.Method.POST;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import com.google.api.services.dataflow.Dataflow;
import com.google.api.services.dataflow.model.Job;
@@ -111,7 +111,7 @@ public class PublishInvoicesAction implements Runnable {
break;
default:
logger.atInfo().log("Job in non-terminal state %s, retrying:", state);
response.setStatus(SC_NOT_MODIFIED);
response.setStatus(SC_SERVICE_UNAVAILABLE);
break;
}
} catch (IOException e) {
@@ -29,6 +29,7 @@ import com.google.common.net.MediaType;
import google.registry.batch.CloudTasksUtils;
import google.registry.bigquery.BigqueryJobFailureException;
import google.registry.config.RegistryConfig.Config;
import google.registry.groups.GmailClient;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.request.Action;
import google.registry.request.Action.Service;
@@ -37,7 +38,6 @@ import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import google.registry.util.SendEmailService;
import java.util.Optional;
import javax.inject.Inject;
import javax.mail.internet.InternetAddress;
@@ -83,8 +83,12 @@ public final class IcannReportingStagingAction implements Runnable {
@Inject Retrier retrier;
@Inject Response response;
@Inject @Config("gSuiteOutgoingEmailAddress") InternetAddress sender;
@Inject @Config("alertRecipientEmailAddress") InternetAddress recipient;
@Inject SendEmailService emailService;
@Inject
@Config("newAlertRecipientEmailAddress")
InternetAddress recipient;
@Inject GmailClient gmailClient;
@Inject CloudTasksUtils cloudTasksUtils;
@Inject IcannReportingStagingAction() {}
@@ -103,7 +107,7 @@ public final class IcannReportingStagingAction implements Runnable {
stager.createAndUploadManifest(subdir, manifestedFiles);
logger.atInfo().log("Completed staging %d report files.", manifestedFiles.size());
emailService.sendEmail(
gmailClient.sendEmail(
EmailMessage.newBuilder()
.setSubject("ICANN Monthly report staging summary [SUCCESS]")
.setBody(
@@ -130,7 +134,7 @@ public final class IcannReportingStagingAction implements Runnable {
},
BigqueryJobFailureException.class);
} catch (Throwable e) {
emailService.sendEmail(
gmailClient.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [FAILURE]",
String.format(
@@ -27,6 +27,7 @@ import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.Config;
import google.registry.gcs.GcsUtils;
import google.registry.groups.GmailClient;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Tld;
@@ -41,7 +42,6 @@ import google.registry.request.lock.LockHandler;
import google.registry.util.Clock;
import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import google.registry.util.SendEmailService;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@@ -87,8 +87,12 @@ public final class IcannReportingUploadAction implements Runnable {
@Inject Retrier retrier;
@Inject Response response;
@Inject @Config("gSuiteOutgoingEmailAddress") InternetAddress sender;
@Inject @Config("alertRecipientEmailAddress") InternetAddress recipient;
@Inject SendEmailService emailService;
@Inject
@Config("newAlertRecipientEmailAddress")
InternetAddress recipient;
@Inject GmailClient gmailClient;
@Inject Clock clock;
@Inject LockHandler lockHandler;
@@ -293,7 +297,7 @@ public final class IcannReportingUploadAction implements Runnable {
(e) ->
String.format("%s - %s", e.getKey(), e.getValue() ? "SUCCESS" : "FAILURE"))
.collect(Collectors.joining("\n")));
emailService.sendEmail(EmailMessage.create(subject, body, recipient, sender));
gmailClient.sendEmail(EmailMessage.create(subject, body, recipient, sender));
}
private byte[] readBytesFromGcs(BlobId reportFilename) throws IOException {
@@ -18,9 +18,9 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.reporting.ReportingModule.PARAM_DATE;
import static google.registry.request.Action.Method.POST;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import com.google.api.services.dataflow.Dataflow;
import com.google.api.services.dataflow.model.Job;
@@ -135,7 +135,7 @@ public class PublishSpec11ReportAction implements Runnable {
break;
default:
logger.atInfo().log("Job in non-terminal state %s, retrying:", state);
response.setStatus(SC_NOT_MODIFIED);
response.setStatus(SC_SERVICE_UNAVAILABLE);
break;
}
} catch (IOException | JSONException e) {
@@ -31,12 +31,12 @@ import com.google.template.soy.tofu.SoyTofu;
import com.google.template.soy.tofu.SoyTofu.Renderer;
import google.registry.beam.spec11.ThreatMatch;
import google.registry.config.RegistryConfig.Config;
import google.registry.groups.GmailClient;
import google.registry.model.domain.Domain;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarPoc;
import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo;
import google.registry.util.EmailMessage;
import google.registry.util.SendEmailService;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
@@ -56,8 +56,7 @@ public class Spec11EmailUtils {
Spec11EmailSoyInfo.getInstance().getFileName()))
.build()
.compileToTofu();
private final SendEmailService emailService;
private final GmailClient gmailClient;
private final InternetAddress outgoingEmailAddress;
private final ImmutableList<InternetAddress> spec11BccEmailAddresses;
private final InternetAddress alertRecipientAddress;
@@ -66,13 +65,13 @@ public class Spec11EmailUtils {
@Inject
Spec11EmailUtils(
SendEmailService emailService,
@Config("alertRecipientEmailAddress") InternetAddress alertRecipientAddress,
GmailClient gmailClient,
@Config("newAlertRecipientEmailAddress") InternetAddress alertRecipientAddress,
@Config("spec11OutgoingEmailAddress") InternetAddress spec11OutgoingEmailAddress,
@Config("spec11BccEmailAddresses") ImmutableList<InternetAddress> spec11BccEmailAddresses,
@Config("spec11WebResources") ImmutableList<String> spec11WebResources,
@Config("registryName") String registryName) {
this.emailService = emailService;
this.gmailClient = gmailClient;
this.outgoingEmailAddress = spec11OutgoingEmailAddress;
this.spec11BccEmailAddresses = spec11BccEmailAddresses;
this.alertRecipientAddress = alertRecipientAddress;
@@ -91,6 +90,7 @@ public class Spec11EmailUtils {
ImmutableSet<RegistrarThreatMatches> registrarThreatMatchesSet) {
ImmutableMap.Builder<RegistrarThreatMatches, Throwable> failedMatchesBuilder =
ImmutableMap.builder();
int numRegistrarsEmailed = 0;
for (RegistrarThreatMatches registrarThreatMatches : registrarThreatMatchesSet) {
RegistrarThreatMatches filteredMatches = filterOutNonPublishedMatches(registrarThreatMatches);
if (!filteredMatches.threatMatches().isEmpty()) {
@@ -98,11 +98,13 @@ public class Spec11EmailUtils {
// Handle exceptions individually per registrar so that one failed email doesn't prevent
// the rest from being sent.
emailRegistrar(date, soyTemplateInfo, subject, filteredMatches);
numRegistrarsEmailed++;
} catch (Throwable e) {
failedMatchesBuilder.put(registrarThreatMatches, getRootCause(e));
}
}
}
logger.atInfo().log("Emailed daily diffs to %s registrars.", numRegistrarsEmailed);
ImmutableMap<RegistrarThreatMatches, Throwable> failedMatches = failedMatchesBuilder.build();
if (!failedMatches.isEmpty()) {
ImmutableList<Map.Entry<RegistrarThreatMatches, Throwable>> failedMatchesList =
@@ -151,7 +153,7 @@ public class Spec11EmailUtils {
String subject,
RegistrarThreatMatches registrarThreatMatches)
throws MessagingException {
emailService.sendEmail(
gmailClient.sendEmail(
EmailMessage.newBuilder()
.setSubject(subject)
.setBody(getContent(date, soyTemplateInfo, registrarThreatMatches))
@@ -191,7 +193,7 @@ public class Spec11EmailUtils {
/** Sends an e-mail indicating the state of the spec11 pipeline, with a given subject and body. */
void sendAlertEmail(String subject, String body) {
try {
emailService.sendEmail(
gmailClient.sendEmail(
EmailMessage.newBuilder()
.setFrom(outgoingEmailAddress)
.addRecipient(alertRecipientAddress)
@@ -31,7 +31,7 @@ import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams;
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.google.protobuf.ByteString;
import dagger.Module;
import dagger.Provides;
@@ -40,6 +40,7 @@ import google.registry.request.HttpException.UnsupportedMediaTypeException;
import google.registry.request.auth.AuthResult;
import google.registry.request.lock.LockHandler;
import google.registry.request.lock.LockHandlerImpl;
import google.registry.tools.GsonUtils;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
@@ -69,6 +70,13 @@ public final class RequestModule {
this.authResult = authResult;
}
@RequestScope
@VisibleForTesting
@Provides
public static Gson provideGson() {
return GsonUtils.provideGson();
}
@Provides
@Parameter(RequestParameters.PARAM_TLD)
static String provideTld(HttpServletRequest req) {
@@ -244,11 +252,11 @@ public final class RequestModule {
@Provides
@OptionalJsonPayload
public static Optional<JsonObject> provideJsonBody(HttpServletRequest req, Gson gson) {
public static Optional<JsonElement> provideJsonBody(HttpServletRequest req, Gson gson) {
try {
JsonObject body = gson.fromJson(req.getReader(), JsonObject.class);
return Optional.of(body);
} catch (Exception e) {
// GET requests return a null reader and thus a null JsonObject, which is fine
return Optional.ofNullable(gson.fromJson(req.getReader(), JsonElement.class));
} catch (IOException e) {
return Optional.empty();
}
}
@@ -16,23 +16,23 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import org.jetbrains.annotations.Nullable;
/** Command to create a PackagePromotion */
/** Command to create a {@link BulkPricingPackage} */
@Parameters(
separators = " =",
commandDescription =
"Create new package promotion object(s) for registrars to register multiple names under"
+ " one contractual annual package price using a package allocation token")
public final class CreatePackagePromotionCommand extends CreateOrUpdatePackagePromotionCommand {
"Create new bulk pricing package object(s) for registrars to register multiple names under"
+ " one contractual annual bulk price using a bulk pricing allocation token")
public final class CreateBulkPricingPackageCommand extends CreateOrUpdateBulkPricingPackageCommand {
@Nullable
@Override
PackagePromotion getOldPackagePromotion(String tokenString) {
BulkPricingPackage getOldBulkPricingPackage(String tokenString) {
checkArgument(
!PackagePromotion.loadByTokenString(tokenString).isPresent(),
"PackagePromotion with token %s already exists",
!BulkPricingPackage.loadByTokenString(tokenString).isPresent(),
"BulkPricingPackage with token %s already exists",
tokenString);
return null;
}
@@ -20,7 +20,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import com.beust.jcommander.Parameter;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.persistence.VKey;
import java.util.Date;
import java.util.List;
@@ -29,39 +29,40 @@ import javax.annotation.Nullable;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** Shared base class for commands to create or update a PackagePromotion object. */
abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
/** Shared base class for commands to create or update a {@link BulkPricingPackage} object. */
abstract class CreateOrUpdateBulkPricingPackageCommand extends MutatingCommand {
@Parameter(description = "Allocation token String of the package token", required = true)
@Parameter(description = "Allocation token String of the bulk token", required = true)
List<String> mainParameters;
@Nullable
@Parameter(
names = {"-d", "--max_domains"},
description = "Maximum concurrent active domains allowed in the package")
description = "Maximum concurrent active domains allowed in the bulk pricing package")
Integer maxDomains;
@Nullable
@Parameter(
names = {"-c", "--max_creates"},
description = "Maximum domain creations allowed in the package each year")
description = "Maximum domain creations allowed in the bulk pricing package each year")
Integer maxCreates;
@Nullable
@Parameter(
names = {"-p", "--price"},
description = "Annual price of the package")
description = "Annual price of the bulk pricing package")
Money price;
@Nullable
@Parameter(
names = "--next_billing_date",
description = "The next date that the package should be billed for its annual fee")
description =
"The next date that the bulk pricing package should be billed for its annual fee")
Date nextBillingDate;
/** Returns the existing PackagePromotion or null if it does not exist. */
/** Returns the existing BulkPricingPackage or null if it does not exist. */
@Nullable
abstract PackagePromotion getOldPackagePromotion(String token);
abstract BulkPricingPackage getOldBulkPricingPackage(String token);
/** Returns the allocation token object. */
AllocationToken getAndCheckAllocationToken(String token) {
@@ -69,12 +70,12 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
checkArgument(
allocationToken.isPresent(),
"An allocation token with the token String %s does not exist. The package token must be"
+ " created first before it can be used to create a PackagePromotion",
"An allocation token with the token String %s does not exist. The bulk token must be"
+ " created first before it can be used to create a BulkPricingPackage",
token);
checkArgument(
allocationToken.get().getTokenType().equals(TokenType.PACKAGE),
"The allocation token must be of the PACKAGE token type");
allocationToken.get().getTokenType().equals(TokenType.BULK_PRICING),
"The allocation token must be of the BULK_PRICING token type");
return allocationToken.get();
}
@@ -88,21 +89,21 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
for (String token : mainParameters) {
tm().transact(
() -> {
PackagePromotion oldPackage = getOldPackagePromotion(token);
BulkPricingPackage oldBulkPricingPackage = getOldBulkPricingPackage(token);
checkArgument(
oldPackage != null || price != null,
"PackagePrice is required when creating a new package");
oldBulkPricingPackage != null || price != null,
"BulkPrice is required when creating a new bulk pricing package");
AllocationToken allocationToken = getAndCheckAllocationToken(token);
PackagePromotion.Builder builder =
(oldPackage == null)
? new PackagePromotion.Builder().setToken(allocationToken)
: oldPackage.asBuilder();
BulkPricingPackage.Builder builder =
(oldBulkPricingPackage == null)
? new BulkPricingPackage.Builder().setToken(allocationToken)
: oldBulkPricingPackage.asBuilder();
Optional.ofNullable(maxDomains).ifPresent(builder::setMaxDomains);
Optional.ofNullable(maxCreates).ifPresent(builder::setMaxCreates);
Optional.ofNullable(price).ifPresent(builder::setPackagePrice);
Optional.ofNullable(price).ifPresent(builder::setBulkPrice);
Optional.ofNullable(nextBillingDate)
.ifPresent(
nextBillingDate ->
@@ -110,8 +111,8 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
if (clearLastNotificationSent()) {
builder.setLastNotificationSent(null);
}
PackagePromotion newPackage = builder.build();
stageEntityChange(oldPackage, newPackage);
BulkPricingPackage newBUlkPricingPackage = builder.build();
stageEntityChange(oldBulkPricingPackage, newBUlkPricingPackage);
});
}
}
@@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEFAULT;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -279,19 +279,20 @@ class GenerateAllocationTokensCommand implements Command {
}
if (!isNullOrEmpty(tokenStatusTransitions)) {
// Don't allow package tokens to be created with a scheduled end time since this could allow
// future domains to be attributed to the package and never be billed. Package promotion
// Don't allow bulk tokens to be created with a scheduled end time since this could allow
// future domains to be attributed to the bulk pricing package and never be billed. Bulk
// tokens should only be scheduled to end with a brief time period before the status
// transition occurs so that no new domains are registered using that token between when the
// status is scheduled and when the transition occurs.
// TODO(@sarahbot): Create a cleaner way to handle ending packages once we actually have
// customers using them
// TODO(@sarahbot): Create a cleaner way to handle ending bulk pricing packages once we
// actually have customers using them
boolean hasEnding =
tokenStatusTransitions.containsValue(TokenStatus.ENDED)
|| tokenStatusTransitions.containsValue(TokenStatus.CANCELLED);
checkArgument(
!(PACKAGE.equals(tokenType) && hasEnding),
"PACKAGE tokens should not be generated with ENDED or CANCELLED in their transition map");
!(BULK_PRICING.equals(tokenType) && hasEnding),
"BULK_PRICING tokens should not be generated with ENDED or CANCELLED in their transition"
+ " map");
}
if (tokenStrings != null) {
@@ -19,14 +19,14 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.List;
/** Command to show a {@link PackagePromotion} object. */
@Parameters(separators = " =", commandDescription = "Show package promotion object(s)")
public class GetPackagePromotionCommand extends GetEppResourceCommand {
/** Command to show a {@link BulkPricingPackage} object. */
@Parameters(separators = " =", commandDescription = "Show bulk pricing package object(s)")
public class GetBulkPricingPackageCommand extends GetEppResourceCommand {
@Parameter(description = "Package token(s)", required = true)
@Parameter(description = "Bulk pricing token(s)", required = true)
private List<String> mainParameters;
@Override
@@ -34,12 +34,12 @@ public class GetPackagePromotionCommand extends GetEppResourceCommand {
for (String token : mainParameters) {
tm().transact(
() -> {
PackagePromotion packagePromotion =
BulkPricingPackage bulkPricingPackage =
checkArgumentPresent(
PackagePromotion.loadByTokenString(token),
"PackagePromotion with package token %s does not exist",
BulkPricingPackage.loadByTokenString(token),
"BulkPricingPackage with token %s does not exist",
token);
System.out.println(packagePromotion);
System.out.println(bulkPricingPackage);
});
}
}
@@ -15,11 +15,17 @@
package google.registry.tools;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import google.registry.model.tld.Tld;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.inject.Inject;
/** Command to show a TLD record. */
@Parameters(separators = " =", commandDescription = "Show TLD record(s)")
@@ -30,10 +36,14 @@ final class GetTldCommand implements Command {
required = true)
private List<String> mainParameters;
@Inject ObjectMapper objectMapper;
@Override
public void run() {
for (String tld : assertTldsExist(mainParameters)) {
System.out.println(Tld.get(tld));
public void run() throws JsonProcessingException, UnsupportedEncodingException {
try (PrintStream printStream = new PrintStream(System.out, false, UTF_8.name())) {
for (String tld : assertTldsExist(mainParameters)) {
printStream.println(objectMapper.writeValueAsString(Tld.get(tld)));
}
}
}
}
@@ -0,0 +1,81 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.tools;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import google.registry.model.adapters.CurrencyJsonAdapter;
import google.registry.util.CidrAddressBlock;
import google.registry.util.CidrAddressBlock.CidrAddressBlockAdapter;
import google.registry.util.DateTimeTypeAdapter;
import java.io.IOException;
import org.joda.money.CurrencyUnit;
import org.joda.time.DateTime;
/** Utility class for methods related to GSON and necessary GSON processing. */
public class GsonUtils {
/** Interface to enable GSON post-processing on a particular object after deserialization. */
public interface GsonPostProcessable {
void postProcess();
}
/**
* Some objects may require post-processing after deserialization from JSON.
*
* <p>We do this upon deserialization in order to make sure that the object matches the format
* that we expect to be stored in the database. See {@link
* google.registry.model.eppcommon.Address} for an example.
*/
public static class GsonPostProcessableTypeAdapterFactory implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
TypeAdapter<T> originalAdapter = gson.getDelegateAdapter(this, type);
if (!GsonPostProcessable.class.isAssignableFrom(type.getRawType())) {
return originalAdapter;
}
return new TypeAdapter<T>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
originalAdapter.write(out, value);
}
@Override
public T read(JsonReader in) throws IOException {
T t = originalAdapter.read(in);
((GsonPostProcessable) t).postProcess();
return t;
}
};
}
}
public static Gson provideGson() {
return new GsonBuilder()
.registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
.registerTypeAdapter(CidrAddressBlock.class, new CidrAddressBlockAdapter())
.registerTypeAdapter(CurrencyUnit.class, new CurrencyJsonAdapter())
.registerTypeAdapterFactory(new GsonPostProcessableTypeAdapterFactory())
.excludeFieldsWithoutExposeAnnotation()
.create();
}
private GsonUtils() {}
}
@@ -36,6 +36,7 @@ public final class RegistryTool {
.put("convert_idn", ConvertIdnCommand.class)
.put("count_domains", CountDomainsCommand.class)
.put("create_anchor_tenant", CreateAnchorTenantCommand.class)
.put("create_bulk_pricing_package", CreateBulkPricingPackageCommand.class)
.put(
"create_cancellations_for_billing_events",
CreateCancellationsForBillingEventsCommand.class)
@@ -43,7 +44,6 @@ public final class RegistryTool {
.put("create_contact", CreateContactCommand.class)
.put("create_domain", CreateDomainCommand.class)
.put("create_host", CreateHostCommand.class)
.put("create_package_promotion", CreatePackagePromotionCommand.class)
.put("create_premium_list", CreatePremiumListCommand.class)
.put("create_registrar", CreateRegistrarCommand.class)
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
@@ -67,13 +67,13 @@ public final class RegistryTool {
.put("generate_lordn", GenerateLordnCommand.class)
.put("generate_zone_files", GenerateZoneFilesCommand.class)
.put("get_allocation_token", GetAllocationTokenCommand.class)
.put("get_bulk_pricing_package", GetBulkPricingPackageCommand.class)
.put("get_claims_list", GetClaimsListCommand.class)
.put("get_contact", GetContactCommand.class)
.put("get_domain", GetDomainCommand.class)
.put("get_history_entries", GetHistoryEntriesCommand.class)
.put("get_host", GetHostCommand.class)
.put("get_keyring_secret", GetKeyringSecretCommand.class)
.put("get_package_promotion", GetPackagePromotionCommand.class)
.put("get_premium_list", GetPremiumListCommand.class)
.put("get_registrar", GetRegistrarCommand.class)
.put("get_reserved_list", GetReservedListCommand.class)
@@ -104,10 +104,10 @@ public final class RegistryTool {
.put("unlock_domain", UnlockDomainCommand.class)
.put("unrenew_domain", UnrenewDomainCommand.class)
.put("update_allocation_tokens", UpdateAllocationTokensCommand.class)
.put("update_bulk_pricing_package", UpdateBulkPricingPackageCommand.class)
.put("update_cursors", UpdateCursorsCommand.class)
.put("update_domain", UpdateDomainCommand.class)
.put("update_keyring_secret", UpdateKeyringSecretCommand.class)
.put("update_package_promotion", UpdatePackagePromotionCommand.class)
.put("update_premium_list", UpdatePremiumListCommand.class)
.put("update_recurrence", UpdateRecurrenceCommand.class)
.put("update_registrar", UpdateRegistrarCommand.class)
@@ -30,10 +30,12 @@ import google.registry.keyring.KeyringModule;
import google.registry.keyring.api.DummyKeyringModule;
import google.registry.keyring.api.KeyModule;
import google.registry.keyring.secretmanager.SecretManagerKeyringModule;
import google.registry.model.ModelModule;
import google.registry.persistence.PersistenceModule;
import google.registry.persistence.PersistenceModule.NomulusToolJpaTm;
import google.registry.persistence.PersistenceModule.ReadOnlyReplicaJpaTm;
import google.registry.persistence.transaction.JpaTransactionManager;
import google.registry.privileges.secretmanager.SecretManagerModule;
import google.registry.rde.RdeModule;
import google.registry.request.Modules.GsonModule;
import google.registry.request.Modules.UrlConnectionServiceModule;
@@ -66,13 +68,14 @@ import javax.inject.Singleton;
GsonModule.class,
KeyModule.class,
KeyringModule.class,
SecretManagerKeyringModule.class,
LocalCredentialModule.class,
ModelModule.class,
PersistenceModule.class,
RdeModule.class,
RegistryToolDataflowModule.class,
RequestFactoryModule.class,
google.registry.privileges.secretmanager.SecretManagerModule.class,
SecretManagerKeyringModule.class,
SecretManagerModule.class,
UrlConnectionServiceModule.class,
UrlFetchServiceModule.class,
UserServiceModule.class,
@@ -117,7 +120,7 @@ interface RegistryToolComponent {
void inject(GetHostCommand command);
void inject(GetPackagePromotionCommand command);
void inject(GetBulkPricingPackageCommand command);
void inject(GetKeyringSecretCommand command);
@@ -169,18 +169,18 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
}
private AllocationToken updateToken(AllocationToken original) {
if (endToken && original.getTokenType().equals(TokenType.PACKAGE)) {
Long domainsInPackage =
tm().query("SELECT COUNT(*) FROM Domain WHERE currentPackageToken = :token", Long.class)
if (endToken && original.getTokenType().equals(TokenType.BULK_PRICING)) {
Long domainsInBulkPackage =
tm().query("SELECT COUNT(*) FROM Domain WHERE currentBulkToken = :token", Long.class)
.setParameter("token", original.createVKey())
.getSingleResult();
checkArgument(
domainsInPackage == 0,
"Package token %s can not end its promotion because it still has %s domains in the"
+ " package",
domainsInBulkPackage == 0,
"Bulk token %s can not end its promotion because it still has %s domains in the"
+ " promotion",
original.getToken(),
domainsInPackage);
domainsInBulkPackage);
}
AllocationToken.Builder builder = original.asBuilder();
Optional.ofNullable(allowedClientIds)
@@ -17,12 +17,12 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.Optional;
/** Command to update a PackagePromotion */
@Parameters(separators = " =", commandDescription = "Update package promotion object(s)")
public final class UpdatePackagePromotionCommand extends CreateOrUpdatePackagePromotionCommand {
/** Command to update a {@link BulkPricingPackage} */
@Parameters(separators = " =", commandDescription = "Update bulk pricing package object(s)")
public final class UpdateBulkPricingPackageCommand extends CreateOrUpdateBulkPricingPackageCommand {
@Parameter(
names = "--clear_last_notification_sent",
@@ -32,10 +32,14 @@ public final class UpdatePackagePromotionCommand extends CreateOrUpdatePackagePr
boolean clearLastNotificationSent;
@Override
PackagePromotion getOldPackagePromotion(String token) {
Optional<PackagePromotion> oldPackage = PackagePromotion.loadByTokenString(token);
checkArgument(oldPackage.isPresent(), "PackagePromotion with token %s does not exist", token);
return oldPackage.get();
BulkPricingPackage getOldBulkPricingPackage(String token) {
Optional<BulkPricingPackage> oldBulkPricingPackage =
BulkPricingPackage.loadByTokenString(token);
checkArgument(
oldBulkPricingPackage.isPresent(),
"BulkPricingPackage with token %s does not exist",
token);
return oldBulkPricingPackage.get();
}
@Override
@@ -14,7 +14,11 @@
package google.registry.ui.server.console;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.POST;
import com.google.api.client.http.HttpStatusCodes;
import com.google.common.collect.ImmutableList;
@@ -23,46 +27,155 @@ import com.google.gson.Gson;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.Registrar.State;
import google.registry.model.registrar.RegistrarPoc;
import google.registry.request.Action;
import google.registry.request.Parameter;
import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.request.auth.AuthResult;
import google.registry.ui.server.registrar.JsonGetAction;
import google.registry.util.StringGenerator;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
@Action(
service = Action.Service.DEFAULT,
path = RegistrarsAction.PATH,
method = {GET},
method = {GET, POST},
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
public class RegistrarsAction implements JsonGetAction {
private static final int PASSWORD_LENGTH = 16;
private static final int PASSCODE_LENGTH = 5;
static final String PATH = "/console-api/registrars";
private final AuthResult authResult;
private final Response response;
private final Gson gson;
private final HttpServletRequest req;
private Optional<Registrar> registrar;
private StringGenerator passwordGenerator;
private StringGenerator passcodeGenerator;
@Inject
public RegistrarsAction(AuthResult authResult, Response response, Gson gson) {
public RegistrarsAction(
HttpServletRequest req,
AuthResult authResult,
Response response,
Gson gson,
@Parameter("registrar") Optional<Registrar> registrar,
@Named("base58StringGenerator") StringGenerator passwordGenerator,
@Named("digitOnlyStringGenerator") StringGenerator passcodeGenerator) {
this.authResult = authResult;
this.response = response;
this.gson = gson;
this.registrar = registrar;
this.req = req;
this.passcodeGenerator = passcodeGenerator;
this.passwordGenerator = passwordGenerator;
}
@Override
public void run() {
User user = authResult.userAuthInfo().get().consoleUser().get();
if (req.getMethod().equals(GET.toString())) {
getHandler(user);
} else {
postHandler(user);
}
}
private void getHandler(User user) {
if (!user.getUserRoles().hasGlobalPermission(ConsolePermission.VIEW_REGISTRARS)) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
return;
}
ImmutableList<String> registrarIds =
ImmutableList<Registrar> registrars =
Streams.stream(Registrar.loadAllCached())
.filter(r -> r.getType() == Registrar.Type.REAL)
.map(Registrar::getRegistrarId)
.collect(ImmutableList.toImmutableList());
response.setPayload(gson.toJson(registrarIds));
response.setPayload(gson.toJson(registrars));
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
}
private void postHandler(User user) {
if (!user.getUserRoles().isAdmin()) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
return;
}
if (!registrar.isPresent()) {
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
response.setPayload(gson.toJson("'registrar' parameter is not present"));
return;
}
Registrar registrarParam = registrar.get();
String errorMsg = "Missing value for %s";
try {
checkArgument(!isNullOrEmpty(registrarParam.getRegistrarId()), errorMsg, "registrarId");
checkArgument(!isNullOrEmpty(registrarParam.getRegistrarName()), errorMsg, "name");
checkArgument(!registrarParam.getBillingAccountMap().isEmpty(), errorMsg, "billingAccount");
checkArgument(registrarParam.getIanaIdentifier() != null, String.format(errorMsg, "ianaId"));
checkArgument(
!isNullOrEmpty(registrarParam.getIcannReferralEmail()), errorMsg, "referralEmail");
checkArgument(!isNullOrEmpty(registrarParam.getDriveFolderId()), errorMsg, "driveId");
checkArgument(!isNullOrEmpty(registrarParam.getEmailAddress()), errorMsg, "consoleUserEmail");
checkArgument(
registrarParam.getLocalizedAddress() != null
&& !isNullOrEmpty(registrarParam.getLocalizedAddress().getState())
&& !isNullOrEmpty(registrarParam.getLocalizedAddress().getCity())
&& !isNullOrEmpty(registrarParam.getLocalizedAddress().getZip())
&& !isNullOrEmpty(registrarParam.getLocalizedAddress().getCountryCode())
&& !registrarParam.getLocalizedAddress().getStreet().isEmpty(),
errorMsg,
"address");
String password = passwordGenerator.createString(PASSWORD_LENGTH);
String phonePasscode = passcodeGenerator.createString(PASSCODE_LENGTH);
Registrar registrar =
new Registrar.Builder()
.setRegistrarId(registrarParam.getRegistrarId())
.setRegistrarName(registrarParam.getRegistrarName())
.setBillingAccountMap(registrarParam.getBillingAccountMap())
.setIanaIdentifier(Long.valueOf(registrarParam.getIanaIdentifier()))
.setIcannReferralEmail(registrarParam.getIcannReferralEmail())
.setEmailAddress(registrarParam.getIcannReferralEmail())
.setDriveFolderId(registrarParam.getDriveFolderId())
.setType(Registrar.Type.REAL)
.setPassword(password)
.setPhonePasscode(phonePasscode)
.setState(State.PENDING)
.setLocalizedAddress(registrarParam.getLocalizedAddress())
.build();
RegistrarPoc contact =
new RegistrarPoc.Builder()
.setRegistrar(registrar)
.setName(registrarParam.getEmailAddress())
.setEmailAddress(registrarParam.getEmailAddress())
.setLoginEmailAddress(registrarParam.getEmailAddress())
.build();
tm().transact(
() -> {
checkArgument(
!Registrar.loadByRegistrarId(registrar.getRegistrarId()).isPresent(),
"Registrar with registrarId %s already exists",
registrar.getRegistrarId());
tm().putAll(registrar, contact);
});
} catch (IllegalArgumentException e) {
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
response.setPayload(gson.toJson(e.getMessage()));
} catch (Throwable e) {
response.setStatus(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
response.setPayload(gson.toJson(e.getMessage()));
}
}
}
@@ -131,7 +131,7 @@ public class ContactAction implements JsonGetAction {
oldContacts,
Collections.singletonMap(
"contacts",
contacts.get().stream().map(c -> c.toJsonMap()).collect(toImmutableList())));
contacts.get().stream().map(RegistrarPoc::toJsonMap).collect(toImmutableList())));
try {
RegistrarSettingsAction.checkContactRequirements(oldContacts, updatedContacts);
} catch (FormException e) {
@@ -15,7 +15,6 @@
package google.registry.ui.server.console.settings;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.POST;
import avro.shaded.com.google.common.collect.ImmutableList;
@@ -36,28 +35,25 @@ import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAcce
import google.registry.ui.server.registrar.JsonGetAction;
import java.util.Optional;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
@Action(
service = Action.Service.DEFAULT,
path = SecurityAction.PATH,
method = {GET, POST},
method = {POST},
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
public class SecurityAction implements JsonGetAction {
static final String PATH = "/console-api/settings/security";
private final HttpServletRequest req;
private final AuthResult authResult;
private final Response response;
private final Gson gson;
private final String registrarId;
private AuthenticatedRegistrarAccessor registrarAccessor;
private Optional<Registrar> registrar;
private CertificateChecker certificateChecker;
private final AuthenticatedRegistrarAccessor registrarAccessor;
private final Optional<Registrar> registrar;
private final CertificateChecker certificateChecker;
@Inject
public SecurityAction(
HttpServletRequest req,
AuthResult authResult,
Response response,
Gson gson,
@@ -65,7 +61,6 @@ public class SecurityAction implements JsonGetAction {
AuthenticatedRegistrarAccessor registrarAccessor,
@Parameter("registrarId") String registrarId,
@Parameter("registrar") Optional<Registrar> registrar) {
this.req = req;
this.authResult = authResult;
this.response = response;
this.gson = gson;
@@ -77,25 +72,6 @@ public class SecurityAction implements JsonGetAction {
@Override
public void run() {
if (req.getMethod().equals(GET.toString())) {
getHandler();
} else {
postHandler();
}
}
private void getHandler() {
try {
Registrar registrar = registrarAccessor.getRegistrar(registrarId);
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
response.setPayload(gson.toJson(registrar));
} catch (RegistrarAccessDeniedException e) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
response.setPayload(e.getMessage());
}
}
private void postHandler() {
User user = authResult.userAuthInfo().get().consoleUser().get();
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
@@ -153,17 +129,15 @@ public class SecurityAction implements JsonGetAction {
registrarParameter
.getClientCertificate()
.ifPresent(
newClientCert -> {
updatedRegistrar.setClientCertificate(newClientCert, tm().getTransactionTime());
});
newClientCert ->
updatedRegistrar.setClientCertificate(newClientCert, tm().getTransactionTime()));
registrarParameter
.getFailoverClientCertificate()
.ifPresent(
failoverCert -> {
updatedRegistrar.setFailoverClientCertificate(
failoverCert, tm().getTransactionTime());
});
failoverCert ->
updatedRegistrar.setFailoverClientCertificate(
failoverCert, tm().getTransactionTime()));
tm().put(updatedRegistrar.build());
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
@@ -0,0 +1,107 @@
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.ui.server.console.settings;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.POST;
import com.google.api.client.http.HttpStatusCodes;
import com.google.gson.Gson;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.Parameter;
import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.request.auth.AuthResult;
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAccessDeniedException;
import google.registry.ui.server.registrar.JsonGetAction;
import java.util.Optional;
import javax.inject.Inject;
/**
* Console action for editing fields on a registrar that are visible in WHOIS/RDAP.
*
* <p>This doesn't cover many of the registrar fields but rather only those that are visible in
* WHOIS/RDAP and don't have any other obvious means of edit.
*/
@Action(
service = Action.Service.DEFAULT,
path = WhoisRegistrarFieldsAction.PATH,
method = {POST},
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
public class WhoisRegistrarFieldsAction implements JsonGetAction {
static final String PATH = "/console-api/settings/whois-fields";
private final AuthResult authResult;
private final Response response;
private final Gson gson;
private AuthenticatedRegistrarAccessor registrarAccessor;
private Optional<Registrar> registrar;
@Inject
public WhoisRegistrarFieldsAction(
AuthResult authResult,
Response response,
Gson gson,
AuthenticatedRegistrarAccessor registrarAccessor,
@Parameter("registrar") Optional<Registrar> registrar) {
this.authResult = authResult;
this.response = response;
this.gson = gson;
this.registrarAccessor = registrarAccessor;
this.registrar = registrar;
}
@Override
public void run() {
if (!registrar.isPresent()) {
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
response.setPayload(gson.toJson("'registrar' parameter is not present"));
return;
}
User user = authResult.userAuthInfo().get().consoleUser().get();
if (!user.getUserRoles()
.hasPermission(
registrar.get().getRegistrarId(), ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
return;
}
tm().transact(() -> loadAndModifyRegistrar(registrar.get()));
}
private void loadAndModifyRegistrar(Registrar providedRegistrar) {
Registrar savedRegistrar;
try {
// reload to make sure the object has all the correct fields
savedRegistrar = registrarAccessor.getRegistrar(providedRegistrar.getRegistrarId());
} catch (RegistrarAccessDeniedException e) {
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
response.setPayload(e.getMessage());
return;
}
Registrar.Builder newRegistrar = savedRegistrar.asBuilder();
newRegistrar.setWhoisServer(providedRegistrar.getWhoisServer());
newRegistrar.setUrl(providedRegistrar.getUrl());
newRegistrar.setLocalizedAddress(providedRegistrar.getLocalizedAddress());
tm().put(newRegistrar.build());
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
}
}
@@ -21,7 +21,7 @@ import static google.registry.request.RequestParameters.extractRequiredParameter
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import dagger.Module;
import dagger.Provides;
import google.registry.model.registrar.Registrar;
@@ -172,15 +172,8 @@ public final class RegistrarConsoleModule {
@Provides
@Parameter("contacts")
public static Optional<ImmutableSet<RegistrarPoc>> provideContacts(
Gson gson, @OptionalJsonPayload Optional<JsonObject> payload) {
if (payload.isPresent() && payload.get().has("contacts")) {
return Optional.of(
ImmutableSet.copyOf(
gson.fromJson(payload.get().get("contacts").getAsJsonArray(), RegistrarPoc[].class)));
}
return Optional.empty();
Gson gson, @OptionalJsonPayload Optional<JsonElement> payload) {
return payload.map(s -> ImmutableSet.copyOf(gson.fromJson(s, RegistrarPoc[].class)));
}
@Provides
@@ -192,11 +185,7 @@ public final class RegistrarConsoleModule {
@Provides
@Parameter("registrar")
public static Optional<Registrar> provideRegistrar(
Gson gson, @OptionalJsonPayload Optional<JsonObject> payload) {
if (payload.isPresent() && payload.get().has("registrar")) {
return Optional.of(gson.fromJson(payload.get().get("registrar"), Registrar.class));
}
return Optional.empty();
Gson gson, @OptionalJsonPayload Optional<JsonElement> payload) {
return payload.map(s -> gson.fromJson(s, Registrar.class));
}
}
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="urn:google:params:xml:ns:bulkToken-1.0"
xmlns:bulkToken="urn:google:params:xml:ns:bulkToken-1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<annotation>
<documentation>
Extensible Provisioning Protocol v1.0
Bulk Token Extension.
</documentation>
</annotation>
<!-- Element used in info command request to get a bulk pricing token for a domain. -->
<element name="info"
type="bulkToken:infoType"/>
<complexType name="infoType"/>
<!-- Element returned in an info command response with a bulk token for a domain with bulk pricing. -->
<element name="bulkData"
type="bulkToken:bulkDataType"/>
<complexType name="bulkDataType">
<sequence>
<element name="token" type="bulkToken:tokenType" maxOccurs="unbounded"/>
</sequence>
</complexType>
<simpleType name="tokenType">
<restriction base="string">
</restriction>
</simpleType>
<!-- End of schema.-->
</schema>
@@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="urn:google:params:xml:ns:packageToken-1.0"
xmlns:packageToken="urn:google:params:xml:ns:packageToken-1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<annotation>
<documentation>
Extensible Provisioning Protocol v1.0
Package Token Extension.
</documentation>
</annotation>
<!-- Element used in info command request to get a package token for a domain. -->
<element name="info"
type="packageToken:infoType"/>
<complexType name="infoType"/>
<!-- Element returned in an info command response with a package token for a package domain. -->
<element name="packageData"
type="packageToken:packageDataType"/>
<complexType name="packageDataType">
<sequence>
<element name="token" type="packageToken:tokenType" maxOccurs="unbounded"/>
</sequence>
</complexType>
<simpleType name="tokenType">
<restriction base="string">
</restriction>
</simpleType>
<!-- End of schema.-->
</schema>
@@ -53,7 +53,7 @@
<class>google.registry.model.domain.secdns.DomainDsData</class>
<class>google.registry.model.domain.secdns.DomainDsDataHistory</class>
<class>google.registry.model.domain.token.AllocationToken</class>
<class>google.registry.model.domain.token.PackagePromotion</class>
<class>google.registry.model.domain.token.BulkPricingPackage</class>
<class>google.registry.model.host.HostHistory</class>
<class>google.registry.model.host.Host</class>
<class>google.registry.model.poll.PollMessage</class>
@@ -32,7 +32,7 @@ import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.contact.Contact;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.DatabaseHelper;
@@ -53,8 +53,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link CheckPackagesComplianceAction}. */
public class CheckPackagesComplianceActionTest {
/** Unit tests for {@link CheckBulkComplianceAction}. */
public class CheckBulkComplianceActionTest {
// This is the default creation time for test data.
private final FakeClock clock = new FakeClock(DateTime.parse("2012-03-25TZ"));
private static final String CREATE_LIMIT_EMAIL_SUBJECT = "create limit subject";
@@ -72,14 +72,14 @@ public class CheckPackagesComplianceActionTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
private CheckPackagesComplianceAction action;
private CheckBulkComplianceAction action;
private AllocationToken token;
private final TestLogHandler logHandler = new TestLogHandler();
private final Logger loggerToIntercept =
Logger.getLogger(CheckPackagesComplianceAction.class.getCanonicalName());
Logger.getLogger(CheckBulkComplianceAction.class.getCanonicalName());
private final SendEmailService emailService = mock(SendEmailService.class);
private Contact contact;
private PackagePromotion packagePromotion;
private BulkPricingPackage bulkPricingPackage;
private SendEmailUtils sendEmailUtils;
private ArgumentCaptor<EmailMessage> emailCaptor = ArgumentCaptor.forClass(EmailMessage.class);
@@ -94,7 +94,7 @@ public class CheckPackagesComplianceActionTest {
emailService);
createTld("tld");
action =
new CheckPackagesComplianceAction(
new CheckBulkComplianceAction(
sendEmailUtils,
clock,
CREATE_LIMIT_EMAIL_SUBJECT,
@@ -108,19 +108,19 @@ public class CheckPackagesComplianceActionTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
packagePromotion =
new PackagePromotion.Builder()
bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setMaxDomains(3)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
@@ -134,46 +134,48 @@ public class CheckPackagesComplianceActionTest {
}
@Test
void testSuccess_noPackageOverCreateLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_noBulkPackageOverCreateLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
verifyNoInteractions(emailService);
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their create limit.");
}
@Test
void testSuccess_onePackageOverCreateLimit() throws Exception {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_oneBulkPackageOverCreateLimit() throws Exception {
tm().transact(() -> tm().put(bulkPricingPackage));
// Create limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their create limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceeded their max domain creation"
+ " limit by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(CREATE_LIMIT_EMAIL_SUBJECT);
@@ -182,92 +184,93 @@ public class CheckPackagesComplianceActionTest {
}
@Test
void testSuccess_multiplePackagesOverCreateLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_multipleBulkPricingPackagesOverCreateLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
// Create limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 2 packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 2 bulk pricing packages over their create limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceeded their max domain creation"
+ " limit by 1 name(s).");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token token has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token token has exceeded their max domain creation"
+ " limit by 1 name(s).");
verify(emailService, times(2)).sendEmail(any(EmailMessage.class));
}
@Test
void testSuccess_onlyChecksCurrentBillingYear() {
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage packagePromotion2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2015-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
@@ -276,289 +279,300 @@ public class CheckPackagesComplianceActionTest {
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their create limit.");
verifyNoInteractions(emailService);
}
@Test
void testSuccess_noPackageOverActiveDomainsLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_noBulkPricingPackageOverActiveDomainsLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
verifyNoInteractions(emailService);
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their active domains limit.");
}
@Test
void testSuccess_onePackageOverActiveDomainsLimit() {
packagePromotion = packagePromotion.asBuilder().setMaxCreates(4).setMaxDomains(1).build();
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_oneBulkPricingPackageOverActiveDomainsLimit() {
bulkPricingPackage = bulkPricingPackage.asBuilder().setMaxCreates(4).setMaxDomains(1).build();
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(4)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_WARNING_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_WARNING_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
@Test
void testSuccess_multiplePackagesOverActiveDomainsLimit() {
void testSuccess_multipleBulkPricingPackagesOverActiveDomainsLimit() {
tm().transact(
() -> tm().put(packagePromotion.asBuilder().setMaxDomains(1).setMaxCreates(4).build()));
() ->
tm().put(bulkPricingPackage.asBuilder().setMaxDomains(1).setMaxCreates(4).build()));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(1)
.setMaxCreates(5)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 2 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 2 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token token has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token token has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService, times(2)).sendEmail(any(EmailMessage.class));
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarningEmail_DoesNotSendAgain() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarningEmail_DoesNotSendAgain() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(5))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verifyNoInteractions(emailService);
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get())
.isEqualTo(clock.nowUtc().minusDays(5));
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarningEmailOver40DaysAgo_SendsAgain() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarningEmailOver40DaysAgo_SendsAgain() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(45))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_WARNING_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_WARNING_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarning30DaysAgo_SendsUpgradeEmail() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarning30DaysAgo_SendsUpgradeEmail() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(31))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_UPGRADE_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_UPGRADE_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
}
@@ -1,174 +0,0 @@
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.beam.common;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth;
import google.registry.beam.TestPipelineExtension;
import google.registry.beam.common.RegistryJpaIO.Read;
import google.registry.model.tld.Tld;
import google.registry.persistence.NomulusPostgreSql;
import google.registry.persistence.PersistenceModule;
import google.registry.persistence.transaction.CriteriaQueryBuilder;
import google.registry.persistence.transaction.JpaTransactionManager;
import google.registry.persistence.transaction.JpaTransactionManagerImpl;
import google.registry.persistence.transaction.TransactionManagerFactory;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import javax.persistence.Persistence;
import org.apache.beam.sdk.coders.SerializableCoder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.values.PCollection;
import org.hibernate.cfg.Environment;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
/** Unit tests for {@link DatabaseSnapshot}. */
@Testcontainers
public class DatabaseSnapshotTest {
/**
* Directly start a PSQL database instead of going through the test extensions.
*
* <p>For reasons unknown, an EntityManagerFactory created by {@code JpaIntegrationTestExtension}
* or {@code JpaUnitTestExtension} enters a bad state after exporting the first snapshot. Starting
* with the second attempt, exports alternate between error ("cannot export a snapshot from a
* subtransaction") and success. The {@link #createSnapshot_twiceNoRead} test below fails with
* either extension. EntityManagerFactory created for production does not have this problem.
*/
@Container
private static PostgreSQLContainer sqlContainer =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())
.withInitScript("sql/schema/nomulus.golden.sql");
@RegisterExtension
final transient TestPipelineExtension testPipeline =
TestPipelineExtension.create().enableAbandonedNodeEnforcement(true);
static JpaTransactionManager origJpa;
static JpaTransactionManager jpa;
static Tld registry;
@BeforeAll
static void setup() {
ImmutableMap<String, String> jpaProperties =
new ImmutableMap.Builder<String, String>()
.put(Environment.URL, sqlContainer.getJdbcUrl())
.put(Environment.USER, sqlContainer.getUsername())
.put(Environment.PASS, sqlContainer.getPassword())
.putAll(PersistenceModule.provideDefaultDatabaseConfigs())
.build();
jpa =
new JpaTransactionManagerImpl(
Persistence.createEntityManagerFactory("nomulus", jpaProperties), new FakeClock());
origJpa = tm();
TransactionManagerFactory.setJpaTm(() -> jpa);
Tld tld = DatabaseHelper.newTld("tld", "TLD");
tm().transact(() -> tm().put(tld));
registry = tm().transact(() -> tm().loadByEntity(tld));
}
@AfterAll
static void tearDown() {
TransactionManagerFactory.setJpaTm(() -> origJpa);
if (jpa != null) {
jpa.teardown();
}
}
@Test
void createSnapshot_onceNoRead() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {}
}
@Test
void createSnapshot_twiceNoRead() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {}
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {}
}
@Test
void readSnapshot() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {
Tld snapshotRegistry =
tm().transact(
() ->
tm().setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
.loadByEntity(registry));
Truth.assertThat(snapshotRegistry).isEqualTo(registry);
}
}
@Test
void readSnapshot_withSubsequentChange() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {
Tld updated =
registry
.asBuilder()
.setCreateBillingCost(registry.getCreateBillingCost().plus(1))
.build();
tm().transact(() -> tm().put(updated));
Tld persistedUpdate = tm().transact(() -> tm().loadByEntity(registry));
Truth.assertThat(persistedUpdate).isNotEqualTo(registry);
Tld snapshotRegistry =
tm().transact(
() ->
tm().setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
.loadByEntity(registry));
Truth.assertThat(snapshotRegistry).isEqualTo(registry);
} finally {
// Revert change to registry in DB, which is shared by all test methods.
tm().transact(() -> tm().put(registry));
}
}
@Test
void readWithRegistryJpaIO() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {
Tld updated =
registry
.asBuilder()
.setCreateBillingCost(registry.getCreateBillingCost().plus(1))
.build();
tm().transact(() -> tm().put(updated));
Read<Tld, Tld> read =
RegistryJpaIO.read(() -> CriteriaQueryBuilder.create(Tld.class).build(), x -> x)
.withCoder(SerializableCoder.of(Tld.class))
.withSnapshot(databaseSnapshot.getSnapshotId());
PCollection<Tld> registries = testPipeline.apply(read);
// This assertion depends on Registry being Serializable, which may change if the
// UnsafeSerializable interface is removed after migration.
PAssert.that(registries).containsInAnyOrder(registry);
testPipeline.run();
} finally {
// Revert change to registry in DB, which is shared by all test methods.
tm().transact(() -> tm().put(registry));
}
}
}
@@ -17,6 +17,7 @@ package google.registry.flows;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.TestDataHelper.loadFile;
import static google.registry.testing.TestLogHandlerUtils.findFirstLogMessageByPrefix;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@@ -30,11 +31,13 @@ import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.testing.TestLogHandler;
import google.registry.config.RegistryConfig;
import google.registry.flows.certs.CertificateChecker;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting;
import google.registry.model.eppoutput.EppResponse;
import google.registry.monitoring.whitebox.EppMetric;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
@@ -46,7 +49,6 @@ import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;
/** Unit tests for {@link FlowRunner}. */
class FlowRunnerTest {
@@ -78,6 +80,21 @@ class FlowRunnerTest {
}
}
static class TestTransactionalFlow implements TransactionalFlow {
private final Optional<TransactionIsolationLevel> isolationLevel;
TestTransactionalFlow(Optional<TransactionIsolationLevel> isolationLevel) {
this.isolationLevel = isolationLevel;
}
@Override
public ResponseOrGreeting run() {
tm().assertTransactionIsolationLevel(
isolationLevel.orElse(tm().getDefaultTransactionIsolationLevel()));
return mock(EppResponse.class);
}
}
@BeforeEach
void beforeEach() {
JdkLoggerConfig.getConfig(FlowRunner.class).addHandler(handler);
@@ -90,23 +107,39 @@ class FlowRunnerTest {
flowRunner.isDryRun = false;
flowRunner.isSuperuser = false;
flowRunner.isTransactional = false;
flowRunner.isolationLevelOverride = Optional.empty();
flowRunner.sessionMetadata =
new StatelessRequestSessionMetadata("TheRegistrar", ImmutableSet.of());
flowRunner.trid = Trid.create("client-123", "server-456");
flowRunner.flowReporter = Mockito.mock(FlowReporter.class);
flowRunner.flowReporter = mock(FlowReporter.class);
}
@Test
void testRun_nonTransactionalCommand_setsCommandNameOnMetric() throws Exception {
flowRunner.isTransactional = true;
flowRunner.run(eppMetricBuilder);
assertThat(eppMetricBuilder.build().getCommandName()).hasValue("TestCommand");
}
@Test
void testRun_transactionalCommand_setsCommandNameOnMetric() throws Exception {
flowRunner.isTransactional = true;
flowRunner.flowClass = TestTransactionalFlow.class;
flowRunner.flowProvider = () -> new TestTransactionalFlow(Optional.empty());
flowRunner.run(eppMetricBuilder);
assertThat(eppMetricBuilder.build().getCommandName()).hasValue("TestCommand");
assertThat(eppMetricBuilder.build().getCommandName()).hasValue("TestTransactional");
}
@Test
void testRun_transactionalCommand_isolationLevelOverride() throws Exception {
flowRunner.isTransactional = true;
flowRunner.isolationLevelOverride =
Optional.of(TransactionIsolationLevel.TRANSACTION_READ_UNCOMMITTED);
flowRunner.flowClass = TestTransactionalFlow.class;
flowRunner.flowProvider = () -> new TestTransactionalFlow(flowRunner.isolationLevelOverride);
if (RegistryConfig.getHibernatePerTransactionIsolationEnabled()) {
flowRunner.run(eppMetricBuilder);
assertThat(eppMetricBuilder.build().getCommandName()).hasValue("TestTransactional");
}
}
@Test
@@ -26,8 +26,8 @@ import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEF
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.NONPREMIUM;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
@@ -78,10 +78,10 @@ import google.registry.flows.FlowUtils.NotLoggedInException;
import google.registry.flows.FlowUtils.UnknownCurrencyEppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.domain.DomainCreateFlow.AnchorTenantCreatePeriodException;
import google.registry.flows.domain.DomainCreateFlow.BulkDomainRegisteredForTooManyYearsException;
import google.registry.flows.domain.DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException;
import google.registry.flows.domain.DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException;
import google.registry.flows.domain.DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException;
import google.registry.flows.domain.DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException;
import google.registry.flows.domain.DomainCreateFlow.RenewalPriceInfo;
import google.registry.flows.domain.DomainCreateFlow.SignedMarksOnlyDuringSunriseException;
import google.registry.flows.domain.DomainFlowTmchUtils.FoundMarkExpiredException;
@@ -3673,12 +3673,12 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
}
@Test
void testSuccess_packageToken_addsTokenToDomain() throws Exception {
void testSuccess_bulkToken_addsTokenToDomain() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
@@ -3696,16 +3696,16 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
.put("EXDATE", "2000-04-03T22:00:00.0Z")
.build()));
Domain domain = reloadResourceByForeignKey();
assertThat(domain.getCurrentPackageToken()).isPresent();
assertThat(domain.getCurrentPackageToken()).hasValue(token.createVKey());
assertThat(domain.getCurrentBulkToken()).isPresent();
assertThat(domain.getCurrentBulkToken()).hasValue(token.createVKey());
}
@Test
void testFailure_packageToken_registrationTooLong() throws Exception {
void testFailure_bulkToken_registrationTooLong() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
@@ -3715,10 +3715,10 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
EppException thrown =
assertThrows(PackageDomainRegisteredForTooManyYearsException.class, this::runFlow);
assertThrows(BulkDomainRegisteredForTooManyYearsException.class, this::runFlow);
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"The package token abc123 cannot be used to register names for longer than 1 year.");
"The bulk token abc123 cannot be used to register names for longer than 1 year.");
}
}
@@ -1085,75 +1085,75 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
}
@Test
void testPackageInfoExtension_returnsPackageInfo() throws Exception {
void testBulkInfoExtension_returnsBulkInfo() throws Exception {
persistTestEntities(false);
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
setEppInput("domain_info_package.xml");
doSuccessfulTest("domain_info_response_package.xml", false);
setEppInput("domain_info_bulk.xml");
doSuccessfulTest("domain_info_response_bulk.xml", false);
}
@Test
void testPackageInfoExtension_returnsPackageInfoForSuperUser() throws Exception {
void testBulkInfoExtension_returnsBulkInfoForSuperUser() throws Exception {
persistTestEntities(false);
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
sessionMetadata.setRegistrarId("TheRegistrar");
setEppInput("domain_info_package.xml");
setEppInput("domain_info_bulk.xml");
EppOutput output = runFlowAsSuperuser();
String expectedOutput =
loadFile(
"domain_info_response_superuser_package.xml",
"domain_info_response_superuser_bulk.xml",
updateSubstitutions(ImmutableMap.of(), "ROID", "2FF-TLD"));
assertXmlEquals(expectedOutput, new String(marshal(output, ValidationMode.LENIENT), UTF_8));
}
@Test
void testPackageInfoExtension_nameNotInPackage() throws Exception {
setEppInput("domain_info_package.xml");
doSuccessfulTest("domain_info_response_empty_package.xml");
void testBulkInfoExtension_nameNotInBulkPackage() throws Exception {
setEppInput("domain_info_bulk.xml");
doSuccessfulTest("domain_info_response_empty_bulk_package.xml");
}
@Test
void testPackageInfoExtension_notCurrentSponsorRegistrar() throws Exception {
void testBulkInfoExtension_notCurrentSponsorRegistrar() throws Exception {
persistTestEntities(false);
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
sessionMetadata.setRegistrarId("TheRegistrar");
setEppInput("domain_info_package.xml");
setEppInput("domain_info_bulk.xml");
doSuccessfulTest("domain_info_response_unauthorized.xml", false);
}
}
@@ -20,8 +20,8 @@ import static google.registry.flows.domain.DomainTransferFlowTestCase.persistWit
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEFAULT;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.NONPREMIUM;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -77,8 +77,8 @@ import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTok
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForTldException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AlreadyRedeemedAllocationTokenException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.InvalidAllocationTokenException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemovePackageTokenOnPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemovePackageTokenOnNonPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnBulkPricingDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonBulkPricingDomainException;
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
import google.registry.model.billing.BillingBase.Flag;
import google.registry.model.billing.BillingBase.Reason;
@@ -1249,123 +1249,111 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
}
@Test
void testFailsPackageDomainInvalidAllocationToken() throws Exception {
void testFailsBulkPricingDomainInvalidAllocationToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain();
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "abc123"));
EppException thrown =
assertThrows(MissingRemovePackageTokenOnPackageDomainException.class, this::runFlow);
assertThrows(MissingRemoveDomainTokenOnBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
void testFailsToRenewPackageDomainNoRemovePackageToken() throws Exception {
void testFailsToRenewBulkPricingDomainNoRemoveDomainToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain();
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput("domain_renew.xml", ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "5"));
EppException thrown =
assertThrows(MissingRemovePackageTokenOnPackageDomainException.class, this::runFlow);
assertThrows(MissingRemoveDomainTokenOnBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
void testFailsToRenewNonPackageDomainWithRemovePackageToken() throws Exception {
void testFailsToRenewNonBulkPricingDomainWithRemoveDomainToken() throws Exception {
persistDomain();
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEPACKAGE__"));
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEDOMAIN__"));
EppException thrown =
assertThrows(RemovePackageTokenOnNonPackageDomainException.class, this::runFlow);
assertThrows(RemoveDomainTokenOnNonBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
void testSuccesfullyAppliesRemovePackageToken() throws Exception {
void testSuccesfullyAppliesRemoveDomainToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEPACKAGE__"));
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEDOMAIN__"));
doSuccessfulTest(
"domain_renew_response.xml",
2,
ImmutableMap.of("DOMAIN", "example.tld", "EXDATE", "2002-04-03T22:00:00Z"));
// We still need to verify that package token is removed as it's not being tested as a part of
// We still need to verify that the bulk token is removed as it's not being tested as a part of
// doSuccessfulTest
Domain domain = reloadResourceByForeignKey();
Truth8.assertThat(domain.getCurrentPackageToken()).isEmpty();
Truth8.assertThat(domain.getCurrentBulkToken()).isEmpty();
}
@Test
void testDryRunRemovePackageToken() throws Exception {
void testDryRunRemoveDomainToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEPACKAGE__"));
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEDOMAIN__"));
dryRunFlowAssertResponse(
loadFile(
@@ -17,7 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.NET_ADDS_4_YR;
@@ -382,12 +382,12 @@ class DomainTransferApproveFlowTest
}
@Test
void testDryRun_PackageDomain() throws Exception {
void testDryRun_bulkPricingDomain() throws Exception {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -398,8 +398,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
persistResource(domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
clock.advanceOneMilli();
setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld"));
dryRunFlowAssertResponse(loadFile("domain_transfer_approve_response.xml"));
@@ -411,12 +410,12 @@ class DomainTransferApproveFlowTest
}
@Test
void testSuccess_removesPackageToken() throws Exception {
void testSuccess_removesBulkToken() throws Exception {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -427,8 +426,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
persistResource(domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
clock.advanceOneMilli();
setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld"));
DateTime now = clock.nowUtc();
@@ -460,7 +458,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
assertThat(domain.getCurrentPackageToken()).isEmpty();
assertThat(domain.getCurrentBulkToken()).isEmpty();
assertThat(domain.getCurrentSponsorRegistrarId()).isEqualTo("NewRegistrar");
assertThat(loadByKey(domain.getAutorenewBillingEvent()).getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.DEFAULT);
@@ -21,7 +21,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_REQUESTED_TIME;
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_RESOURCE_KEY;
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_ACTIONS;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_SUCCESSFUL;
@@ -1329,7 +1329,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_specifiedRenewalPrice_notCarriedOverForPackageName() throws Exception {
void testSuccess_specifiedRenewalPrice_notCarriedOverForBulkPricingName() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1343,13 +1343,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
DateTime now = clock.nowUtc();
setEppInput("domain_transfer_request.xml");
@@ -1388,7 +1388,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_defaultRenewalPrice_carriedOverForPackageName() throws Exception {
void testSuccess_defaultRenewalPrice_carriedOverForBulkPricingName() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1401,13 +1401,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
DateTime now = clock.nowUtc();
setEppInput("domain_transfer_request.xml");
@@ -1445,7 +1445,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_packageName_zeroPeriod() throws Exception {
void testSuccess_bulkPricingName_zeroPeriod() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1458,13 +1458,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml",
@@ -0,0 +1,202 @@
// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// 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.
package google.registry.groups;
import static com.google.common.net.MediaType.CSV_UTF_8;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.api.client.http.HttpResponseException;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.Gmail.Users;
import com.google.api.services.gmail.Gmail.Users.Messages;
import com.google.api.services.gmail.Gmail.Users.Messages.Send;
import com.google.api.services.gmail.model.Message;
import google.registry.groups.GmailClient.RetriableGmailExceptionPredicate;
import google.registry.util.EmailMessage;
import google.registry.util.EmailMessage.Attachment;
import google.registry.util.Retrier;
import google.registry.util.SystemSleeper;
import java.io.OutputStream;
import javax.mail.Message.RecipientType;
import javax.mail.Part;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer;
import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
/** Unit tests for {@link GmailClient}. */
@ExtendWith(MockitoExtension.class)
public class GmailClientTest {
@Mock private Gmail gmail;
@Mock private HttpResponseException httpResponseException;
private GmailClient getGmailClient(boolean isExternalEmailAllowed) throws Exception {
return new GmailClient(
gmail,
new Retrier(new SystemSleeper(), 3),
isExternalEmailAllowed,
"from@example.com",
"My sender",
new InternetAddress("replyTo@example.com"));
}
@Test
public void sendEmail_sentWhenAllowed() throws Exception {
EmailMessage message =
EmailMessage.create(
"subject",
"body",
new InternetAddress("from@example.com"),
new InternetAddress("to@example.com"));
Send gSend = mock(Send.class);
Messages gMessages = mock(Messages.class);
Users gUsers = mock(Users.class);
when(gmail.users()).thenReturn(gUsers);
when(gUsers.messages()).thenReturn(gMessages);
when(gMessages.send(anyString(), any())).thenReturn(gSend);
getGmailClient(true).sendEmail(message);
verify(gmail, times(1)).users();
}
@Test
public void sendEmail_notSentWhenNotAllowed() throws Exception {
EmailMessage message =
EmailMessage.create(
"subject",
"body",
new InternetAddress("from@example.com"),
new InternetAddress("to@example.com"));
getGmailClient(false).sendEmail(message);
verifyNoInteractions(gmail);
}
@Test
public void toMimeMessage_fullMessage() throws Exception {
InternetAddress fromAddr = new InternetAddress("from@example.com", "My sender");
InternetAddress toAddr = new InternetAddress("to@example.com");
InternetAddress ccAddr = new InternetAddress("cc@example.com");
InternetAddress bccAddr = new InternetAddress("bcc@example.com");
EmailMessage emailMessage =
EmailMessage.newBuilder()
.setFrom(fromAddr)
.setRecipients(ImmutableList.of(toAddr))
.setSubject("My subject")
.setBody("My body")
.addCc(ccAddr)
.addBcc(bccAddr)
.setAttachment(
Attachment.newBuilder()
.setFilename("filename")
.setContent("foo,bar\nbaz,qux")
.setContentType(CSV_UTF_8)
.build())
.build();
MimeMessage mimeMessage = getGmailClient(true).toMimeMessage(emailMessage);
assertThat(mimeMessage.getFrom()).asList().containsExactly(fromAddr);
assertThat(mimeMessage.getRecipients(RecipientType.TO)).asList().containsExactly(toAddr);
assertThat(mimeMessage.getRecipients(RecipientType.CC)).asList().containsExactly(ccAddr);
assertThat(mimeMessage.getRecipients(RecipientType.BCC)).asList().containsExactly(bccAddr);
assertThat(mimeMessage.getSubject()).isEqualTo("My subject");
assertThat(mimeMessage.getContent()).isInstanceOf(MimeMultipart.class);
MimeMultipart parts = (MimeMultipart) mimeMessage.getContent();
Part body = parts.getBodyPart(0);
assertThat(body.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8.toString());
assertThat(body.getContent()).isEqualTo("My body");
Part attachment = parts.getBodyPart(1);
assertThat(attachment.getContentType()).startsWith(CSV_UTF_8.toString());
assertThat(attachment.getContentType()).endsWith("name=filename");
assertThat(attachment.getContent()).isEqualTo("foo,bar\nbaz,qux");
}
@Test
public void toGmailMessage() throws Exception {
MimeMessage mimeMessage = mock(MimeMessage.class);
byte[] data = "My content".getBytes(UTF_8);
doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
OutputStream os = invocation.getArgument(0);
os.write(data);
return null;
}
})
.when(mimeMessage)
.writeTo(any(OutputStream.class));
Message gmailMessage = GmailClient.toGmailMessage(mimeMessage);
assertThat(gmailMessage.decodeRaw()).isEqualTo(data);
}
@Test
public void isRetriable_trueIfNotHttpResponseException() {
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(new Exception())).isTrue();
}
@Test
public void isHttpResponseExceptionRetriable_trueIf500() {
when(httpResponseException.getStatusCode()).thenReturn(500);
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isTrue();
}
@Test
public void isHttpResponseExceptionRetriable_trueIf429() {
when(httpResponseException.getStatusCode()).thenReturn(429);
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isTrue();
}
@Test
public void isHttpResponseExceptionRetriable_trueIf403WithRateLimitOverage() {
when(httpResponseException.getStatusCode()).thenReturn(403);
when(httpResponseException.getStatusMessage()).thenReturn("rateLimitExceeded");
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isTrue();
}
@Test
public void isHttpResponseExceptionRetriable_trueIf403WithUserRateLimitOverage() {
when(httpResponseException.getStatusCode()).thenReturn(403);
when(httpResponseException.getStatusMessage()).thenReturn("userRateLimitExceeded");
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isTrue();
}
@Test
public void isHttpResponseExceptionRetriable_falseIf403WithLongLastingOverage() {
when(httpResponseException.getStatusCode()).thenReturn(403);
when(httpResponseException.getStatusMessage()).thenReturn("dailyLimitExceeded");
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isFalse();
}
@Test
public void isHttpResponseExceptionRetriable_falseIfBadRequest() {
when(httpResponseException.getStatusCode()).thenReturn(400);
assertThat(RetriableGmailExceptionPredicate.INSTANCE.test(httpResponseException)).isFalse();
}
}
@@ -17,7 +17,7 @@ package google.registry.model.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
@@ -131,7 +131,7 @@ public class DomainSqlTest {
allocationToken =
new AllocationToken.Builder()
.setToken("abc123Unlimited")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("dev", "app"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -152,9 +152,9 @@ public class DomainSqlTest {
}
@Test
void testDomainBasePersistenceWithCurrentPackageToken() {
void testDomainBasePersistenceWithCurrentBulkToken() {
persistResource(allocationToken);
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build();
persistDomain();
assertEqualDomainExcept(loadByKey(domain.createVKey()));
}
@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatabaseHelper.createTld;
@@ -812,7 +812,7 @@ public class DomainTest {
}
@Test
void testClone_removesPackageFromTransferredDomain() {
void testClone_removesBulkTokenFromTransferredDomain() {
// If the transfer implicitly succeeded, the expiration time should be extended even if it
// hadn't already expired
DateTime now = DateTime.now(UTC);
@@ -831,7 +831,7 @@ public class DomainTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -841,13 +841,13 @@ public class DomainTest {
.asBuilder()
.setRegistrationExpirationTime(previousExpiration)
.setTransferData(transferData)
.setCurrentPackageToken(allocationToken.createVKey())
.setCurrentBulkToken(allocationToken.createVKey())
.build());
assertThat(domain.getCurrentPackageToken()).isPresent();
assertThat(domain.getCurrentBulkToken()).isPresent();
Domain clonedDomain = domain.cloneProjectedAtTime(now);
assertThat(clonedDomain.getRegistrationExpirationTime()).isEqualTo(newExpiration);
assertThat(clonedDomain.getCurrentPackageToken()).isEmpty();
assertThat(clonedDomain.getCurrentBulkToken()).isEmpty();
}
@Test
@@ -876,7 +876,7 @@ public class DomainTest {
}
@Test
void testClone_doesNotRemovePackageForPendingTransfer() {
void testClone_doesNotRemoveBulkTokenForPendingTransfer() {
// Pending transfers shouldn't affect the expiration time
DateTime now = DateTime.now(UTC);
DateTime transferExpirationTime = now.plusDays(1);
@@ -892,7 +892,7 @@ public class DomainTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -902,12 +902,12 @@ public class DomainTest {
.asBuilder()
.setRegistrationExpirationTime(previousExpiration)
.setTransferData(transferData)
.setCurrentPackageToken(allocationToken.createVKey())
.setCurrentBulkToken(allocationToken.createVKey())
.build());
Domain clonedDomain = domain.cloneProjectedAtTime(now);
assertThat(clonedDomain.getRegistrationExpirationTime()).isEqualTo(previousExpiration);
assertThat(clonedDomain.getCurrentPackageToken().get()).isEqualTo(allocationToken.createVKey());
assertThat(clonedDomain.getCurrentBulkToken().get()).isEqualTo(allocationToken.createVKey());
}
@Test
@@ -1043,48 +1043,48 @@ public class DomainTest {
}
@Test
void testFail_currentPackageTokenWrongPackageType() {
void testFail_currentBulkTokenWrongTokenType() {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
() -> domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
assertThat(thrown)
.hasMessageThat()
.isEqualTo("The currentPackageToken must have a PACKAGE TokenType");
.isEqualTo("The currentBulkToken must have a BULK_PRICING TokenType");
}
@Test
void testFailure_packageTokenDoesNotExist() {
void testFailure_bulkTokenDoesNotExist() {
AllocationToken allocationToken =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build();
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
assertThat(thrown).hasMessageThat().isEqualTo("The package token abc123 does not exist");
() -> domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
assertThat(thrown).hasMessageThat().isEqualTo("The bulk token abc123 does not exist");
}
@Test
void testSuccess_removeCurrentPackageToken() {
void testSuccess_removeCurrentBulkToken() {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
assertThat(domain.getCurrentPackageToken().get()).isEqualTo(allocationToken.createVKey());
domain = domain.asBuilder().setCurrentPackageToken(null).build();
assertThat(domain.getCurrentPackageToken()).isEmpty();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build();
assertThat(domain.getCurrentBulkToken().get()).isEqualTo(allocationToken.createVKey());
domain = domain.asBuilder().setCurrentBulkToken(null).build();
assertThat(domain.getCurrentBulkToken()).isEmpty();
}
}
@@ -20,7 +20,7 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.CAN
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.testing.DatabaseHelper.createTld;
@@ -218,28 +218,28 @@ public class AllocationTokenTest extends EntityTestCase {
}
@Test
void testFail_packageTokenNotSpecifiedRenewalBehavior() {
void testFail_bulkTokenNotSpecifiedRenewalBehavior() {
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Package tokens must have renewalPriceBehavior set to SPECIFIED");
.isEqualTo("Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
}
@Test
void testFail_packageTokenDiscountPremium() {
void testFail_bulkTokenDiscountPremium() {
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountPremiums(true);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown).hasMessageThat().isEqualTo("Package tokens cannot discount premium names");
assertThat(thrown).hasMessageThat().isEqualTo("Bulk tokens cannot discount premium names");
}
@Test
@@ -292,17 +292,17 @@ public class AllocationTokenTest extends EntityTestCase {
}
@Test
void testBuild_onlyOneClientInPackage() {
void testBuild_onlyOneClientInBulkPricingPackage() {
Buildable.Builder<AllocationToken> builder =
new AllocationToken.Builder()
.setToken("foobar")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("foo", "bar"));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("PACKAGE tokens must have exactly one allowed client registrar");
.isEqualTo("BULK_PRICING tokens must have exactly one allowed client registrar");
}
@Test
@@ -31,10 +31,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link PackagePromotion}. */
public class PackagePromotionTest extends EntityTestCase {
/** Unit tests for {@link BulkPricingPackage}. */
public class BulkPricingPackageTest extends EntityTestCase {
public PackagePromotionTest() {
public BulkPricingPackageTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@@ -49,7 +49,7 @@ public class PackagePromotionTest extends EntityTestCase {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -57,23 +57,23 @@ public class PackagePromotionTest extends EntityTestCase {
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
assertAboutImmutableObjects()
.that(tm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get())
.isEqualExceptFields(packagePromotion, "packagePromotionId");
.that(tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123")).get())
.isEqualExceptFields(bulkPricingPackage, "bulkPricingId");
}
@Test
void testFail_tokenIsNotPackage() {
void testFail_tokenIsNotBulkToken() {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
@@ -90,14 +90,14 @@ public class PackagePromotionTest extends EntityTestCase {
IllegalArgumentException.class,
() ->
persistResource(
new PackagePromotion.Builder()
new BulkPricingPackage.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build()));
assertThat(thrown).hasMessageThat().isEqualTo("Allocation token must be a PACKAGE type");
assertThat(thrown).hasMessageThat().isEqualTo("Allocation token must be a BULK_PRICING type");
}
}
@@ -17,6 +17,7 @@ package google.registry.model.tld;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EntityYamlUtils.createObjectMapper;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
@@ -24,17 +25,16 @@ import static google.registry.model.tld.Tld.TldState.GENERAL_AVAILABILITY;
import static google.registry.model.tld.Tld.TldState.PREDELEGATION;
import static google.registry.model.tld.Tld.TldState.QUIET_PERIOD;
import static google.registry.model.tld.Tld.TldState.START_DATE_SUNRISE;
import static google.registry.model.tld.TldYamlUtils.getObjectMapper;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.newTld;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistReservedList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.TestDataHelper.filePath;
import static google.registry.testing.TestDataHelper.loadFile;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.ResourceUtils.readResourceBytes;
import static java.math.RoundingMode.UNNECESSARY;
import static org.joda.money.CurrencyUnit.EUR;
import static org.joda.money.CurrencyUnit.USD;
@@ -55,7 +55,6 @@ import google.registry.model.tld.label.ReservedList;
import google.registry.persistence.VKey;
import google.registry.tldconfig.idn.IdnTableEnum;
import google.registry.util.SerializeUtils;
import java.io.File;
import java.math.BigDecimal;
import java.util.Optional;
import org.joda.money.Money;
@@ -130,7 +129,7 @@ public final class TldTest extends EntityTestCase {
.setIdnTables(ImmutableSet.of(IdnTableEnum.JA, IdnTableEnum.EXTENDED_LATIN))
.build();
ObjectMapper mapper = getObjectMapper();
ObjectMapper mapper = createObjectMapper();
String yaml = mapper.writeValueAsString(existingTld);
assertThat(yaml).isEqualTo(loadFile(getClass(), "tld.yaml"));
}
@@ -163,15 +162,16 @@ public final class TldTest extends EntityTestCase {
.setIdnTables(ImmutableSet.of(IdnTableEnum.JA, IdnTableEnum.EXTENDED_LATIN))
.build();
ObjectMapper mapper = getObjectMapper();
Tld constructedTld = mapper.readValue(new File(filePath(getClass(), "tld.yaml")), Tld.class);
ObjectMapper mapper = createObjectMapper();
Tld constructedTld =
mapper.readValue(readResourceBytes(getClass(), "tld.yaml").openBufferedStream(), Tld.class);
compareTlds(existingTld, constructedTld);
}
@Test
void testSuccess_tldYamlRoundtrip() throws Exception {
Tld testTld = createTld("test");
ObjectMapper mapper = getObjectMapper();
ObjectMapper mapper = createObjectMapper();
String yaml = mapper.writeValueAsString(testTld);
Tld constructedTld = mapper.readValue(yaml, Tld.class);
compareTlds(testTld, constructedTld);
@@ -16,6 +16,8 @@ package google.registry.persistence.transaction;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_READ_UNCOMMITTED;
import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.assertDetachedFromEntityManager;
import static google.registry.testing.DatabaseHelper.existsInDb;
@@ -31,6 +33,7 @@ import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.config.RegistryConfig;
import google.registry.model.ImmutableObject;
import google.registry.persistence.VKey;
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
@@ -81,7 +84,7 @@ class JpaTransactionManagerImplTest {
.buildUnitTestExtension();
@Test
void transact_succeeds() {
void transact_success() {
assertPersonEmpty();
assertCompanyEmpty();
tm().transact(
@@ -89,6 +92,7 @@ class JpaTransactionManagerImplTest {
insertPerson(10);
insertCompany("Foo");
insertCompany("Bar");
tm().assertTransactionIsolationLevel(tm().getDefaultTransactionIsolationLevel());
});
assertPersonCount(1);
assertPersonExist(10);
@@ -97,6 +101,52 @@ class JpaTransactionManagerImplTest {
assertCompanyExist("Bar");
}
@Test
void transact_setIsolationLevel() {
tm().transact(
() -> {
tm().assertTransactionIsolationLevel(
RegistryConfig.getHibernatePerTransactionIsolationEnabled()
? TRANSACTION_READ_UNCOMMITTED
: tm().getDefaultTransactionIsolationLevel());
return null;
},
TRANSACTION_READ_UNCOMMITTED);
// Make sure that we can start a new transaction on the same thread with a different isolation
// level.
tm().transact(
() -> {
tm().assertTransactionIsolationLevel(
RegistryConfig.getHibernatePerTransactionIsolationEnabled()
? TRANSACTION_REPEATABLE_READ
: tm().getDefaultTransactionIsolationLevel());
return null;
},
TRANSACTION_REPEATABLE_READ);
}
@Test
void transact_nestedTransactions() {
// Unit tests always allows for per-transaction isolation level (and therefore throws when a
// nested transaction is detected).
if (RegistryConfig.getHibernatePerTransactionIsolationEnabled()) {
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,
() ->
tm().transact(
() -> {
tm().transact(() -> {});
}));
assertThat(e).hasMessageThat().isEqualTo("Nested transaction detected");
} else {
tm().transact(
() -> {
tm().transact(() -> {});
});
}
}
@Test
void transact_hasNoEffectWithPartialSuccess() {
assertPersonEmpty();
@@ -606,19 +656,19 @@ class JpaTransactionManagerImplTest {
verify(spyJpaTm, times(3)).delete(theEntityKey);
}
private void insertPerson(int age) {
private static void insertPerson(int age) {
tm().getEntityManager()
.createNativeQuery(String.format("INSERT INTO Person (age) VALUES (%d)", age))
.executeUpdate();
}
private void insertCompany(String name) {
private static void insertCompany(String name) {
tm().getEntityManager()
.createNativeQuery(String.format("INSERT INTO Company (name) VALUES ('%s')", name))
.executeUpdate();
}
private void assertPersonExist(int age) {
private static void assertPersonExist(int age) {
tm().transact(
() -> {
EntityManager em = tm().getEntityManager();
@@ -631,7 +681,7 @@ class JpaTransactionManagerImplTest {
});
}
private void assertCompanyExist(String name) {
private static void assertCompanyExist(String name) {
tm().transact(
() -> {
String maybeName =
@@ -644,23 +694,23 @@ class JpaTransactionManagerImplTest {
});
}
private void assertPersonCount(int count) {
private static void assertPersonCount(int count) {
assertThat(countTable("Person")).isEqualTo(count);
}
private void assertCompanyCount(int count) {
private static void assertCompanyCount(int count) {
assertThat(countTable("Company")).isEqualTo(count);
}
private void assertPersonEmpty() {
private static void assertPersonEmpty() {
assertPersonCount(0);
}
private void assertCompanyEmpty() {
private static void assertCompanyEmpty() {
assertCompanyCount(0);
}
private int countTable(String tableName) {
private static int countTable(String tableName) {
return tm().transact(
() -> {
BigInteger colCount =
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject;
import google.registry.persistence.PersistenceModule.TransactionIsolationLevel;
import google.registry.persistence.VKey;
import java.util.Optional;
import java.util.function.Supplier;
@@ -49,6 +50,21 @@ public class ReplicaSimulatingJpaTransactionManager implements JpaTransactionMan
delegate.teardown();
}
@Override
public TransactionIsolationLevel getDefaultTransactionIsolationLevel() {
return delegate.getDefaultTransactionIsolationLevel();
}
@Override
public TransactionIsolationLevel getCurrentTransactionIsolationLevel() {
return delegate.getCurrentTransactionIsolationLevel();
}
@Override
public void assertTransactionIsolationLevel(TransactionIsolationLevel expectedLevel) {
delegate.assertTransactionIsolationLevel(expectedLevel);
}
@Override
public EntityManager getStandaloneEntityManager() {
return delegate.getStandaloneEntityManager();
@@ -59,11 +75,6 @@ public class ReplicaSimulatingJpaTransactionManager implements JpaTransactionMan
return delegate.getEntityManager();
}
@Override
public JpaTransactionManager setDatabaseSnapshot(String snapshotId) {
return delegate.setDatabaseSnapshot(snapshotId);
}
@Override
public <T> TypedQuery<T> query(String sqlString, Class<T> resultClass) {
return delegate.query(sqlString, resultClass);
@@ -90,7 +101,7 @@ public class ReplicaSimulatingJpaTransactionManager implements JpaTransactionMan
}
@Override
public <T> T transact(Supplier<T> work) {
public <T> T transact(Supplier<T> work, TransactionIsolationLevel isolationLevel) {
if (delegate.inTransaction()) {
return work.get();
}
@@ -101,26 +112,48 @@ public class ReplicaSimulatingJpaTransactionManager implements JpaTransactionMan
.createNativeQuery("SET TRANSACTION READ ONLY")
.executeUpdate();
return work.get();
});
},
isolationLevel);
}
@Override
public <T> T transact(Supplier<T> work) {
return transact(work, null);
}
@Override
public <T> T transactNoRetry(Supplier<T> work, TransactionIsolationLevel isolationLevel) {
return transact(work, isolationLevel);
}
@Override
public <T> T transactNoRetry(Supplier<T> work) {
return transact(work);
return transactNoRetry(work, null);
}
@Override
public void transact(Runnable work) {
public void transact(Runnable work, TransactionIsolationLevel isolationLevel) {
transact(
() -> {
work.run();
return null;
});
},
isolationLevel);
}
@Override
public void transact(Runnable work) {
transact(work, null);
}
@Override
public void transactNoRetry(Runnable work, TransactionIsolationLevel isolationLevel) {
transact(work, isolationLevel);
}
@Override
public void transactNoRetry(Runnable work) {
transact(work);
transactNoRetry(work, null);
}
@Override
@@ -16,9 +16,9 @@ package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -101,7 +101,7 @@ class PublishInvoicesActionTest {
void testJobIndeterminate_returnsRetriableResponse() {
expectedJob.setCurrentState("JOB_STATE_RUNNING");
uploadAction.run();
assertThat(response.getStatus()).isEqualTo(SC_NOT_MODIFIED);
assertThat(response.getStatus()).isEqualTo(SC_SERVICE_UNAVAILABLE);
}
@Test
@@ -25,6 +25,7 @@ import com.google.cloud.tasks.v2.HttpMethod;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.bigquery.BigqueryJobFailureException;
import google.registry.groups.GmailClient;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.CloudTasksHelper;
@@ -34,7 +35,6 @@ import google.registry.testing.FakeResponse;
import google.registry.testing.FakeSleeper;
import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import google.registry.util.SendEmailService;
import java.util.Optional;
import javax.mail.internet.InternetAddress;
import org.joda.time.DateTime;
@@ -65,7 +65,7 @@ class IcannReportingStagingActionTest {
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.sender = new InternetAddress("sender@example.com");
action.recipient = new InternetAddress("recipient@example.com");
action.emailService = mock(SendEmailService.class);
action.gmailClient = mock(GmailClient.class);
action.cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
when(stager.stageReports(yearMonth, subdir, ReportType.ACTIVITY))
@@ -89,7 +89,7 @@ class IcannReportingStagingActionTest {
action.run();
verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b"));
verify(action.emailService)
verify(action.gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
@@ -105,7 +105,7 @@ class IcannReportingStagingActionTest {
verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(stager).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS);
verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d"));
verify(action.emailService)
verify(action.gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
@@ -124,7 +124,7 @@ class IcannReportingStagingActionTest {
verify(stager, times(2)).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(stager, times(2)).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS);
verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d"));
verify(action.emailService)
verify(action.gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
@@ -147,7 +147,7 @@ class IcannReportingStagingActionTest {
.hasMessageThat()
.isEqualTo("BigqueryJobFailureException: Expected failure");
verify(stager, times(3)).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(action.emailService)
verify(action.gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [FAILURE]",
@@ -31,6 +31,7 @@ import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
import com.google.common.testing.TestLogHandler;
import google.registry.gcs.GcsUtils;
import google.registry.groups.GmailClient;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Tld;
@@ -43,7 +44,6 @@ import google.registry.testing.FakeResponse;
import google.registry.testing.FakeSleeper;
import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import google.registry.util.SendEmailService;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -63,7 +63,7 @@ class IcannReportingUploadActionTest {
private static final byte[] PAYLOAD_SUCCESS = "test,csv\n13,37".getBytes(UTF_8);
private static final byte[] PAYLOAD_FAIL = "ahah,csv\n12,34".getBytes(UTF_8);
private final IcannHttpReporter mockReporter = mock(IcannHttpReporter.class);
private final SendEmailService emailService = mock(SendEmailService.class);
private final GmailClient gmailClient = mock(GmailClient.class);
private final FakeResponse response = new FakeResponse();
private final GcsUtils gcsUtils = new GcsUtils(LocalStorageHelper.getOptions());
private final TestLogHandler logHandler = new TestLogHandler();
@@ -77,7 +77,7 @@ class IcannReportingUploadActionTest {
action.gcsUtils = gcsUtils;
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.reportingBucket = "basin";
action.emailService = emailService;
action.gmailClient = gmailClient;
action.sender = new InternetAddress("sender@example.com");
action.recipient = new InternetAddress("recipient@example.com");
action.response = response;
@@ -127,7 +127,7 @@ class IcannReportingUploadActionTest {
verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv");
verifyNoMoreInteractions(mockReporter);
verify(emailService)
verify(gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
@@ -162,7 +162,7 @@ class IcannReportingUploadActionTest {
verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200512.csv");
verifyNoMoreInteractions(mockReporter);
verify(emailService)
verify(gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report upload summary: 2/2 succeeded",
@@ -191,7 +191,7 @@ class IcannReportingUploadActionTest {
IcannReportingUploadAction action = createAction();
action.run();
verifyNoMoreInteractions(mockReporter);
verifyNoMoreInteractions(emailService);
verifyNoMoreInteractions(gmailClient);
}
@Test
@@ -206,7 +206,7 @@ class IcannReportingUploadActionTest {
verify(mockReporter).send(PAYLOAD_SUCCESS, "foo-transactions-200606.csv");
verify(mockReporter, times(2)).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv");
verifyNoMoreInteractions(mockReporter);
verify(emailService)
verify(gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
@@ -266,7 +266,7 @@ class IcannReportingUploadActionTest {
verify(mockReporter).send(PAYLOAD_SUCCESS, "foo-transactions-200606.csv");
verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv");
verifyNoMoreInteractions(mockReporter);
verify(emailService)
verify(gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
@@ -336,7 +336,7 @@ class IcannReportingUploadActionTest {
verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv");
verifyNoMoreInteractions(mockReporter);
verify(emailService)
verify(gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
@@ -19,9 +19,9 @@ import static google.registry.reporting.spec11.Spec11RegistrarThreatMatchesParse
import static google.registry.reporting.spec11.Spec11RegistrarThreatMatchesParserTest.getMatchB;
import static google.registry.reporting.spec11.Spec11RegistrarThreatMatchesParserTest.sampleThreatMatches;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -134,7 +134,7 @@ class PublishSpec11ReportActionTest {
void testJobIndeterminate_returnsRetriableResponse() {
expectedJob.setCurrentState("JOB_STATE_RUNNING");
publishAction.run();
assertThat(response.getStatus()).isEqualTo(SC_NOT_MODIFIED);
assertThat(response.getStatus()).isEqualTo(SC_SERVICE_UNAVAILABLE);
verifyNoMoreInteractions(emailUtils);
}
@@ -27,14 +27,13 @@ import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType;
import google.registry.groups.GmailClient;
import google.registry.model.domain.Domain;
import google.registry.model.host.Host;
import google.registry.persistence.transaction.JpaTestExtensions;
@@ -42,7 +41,6 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo;
import google.registry.testing.DatabaseHelper;
import google.registry.util.EmailMessage;
import google.registry.util.SendEmailService;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
@@ -51,10 +49,14 @@ import javax.mail.internet.InternetAddress;
import org.joda.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
/** Unit tests for {@link Spec11EmailUtils}. */
@ExtendWith(MockitoExtension.class)
class Spec11EmailUtilsTest {
private static final ImmutableList<String> FAKE_RESOURCES = ImmutableList.of("foo");
@@ -98,9 +100,8 @@ class Spec11EmailUtilsTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
private SendEmailService emailService;
@Mock private GmailClient gmailClient;
private Spec11EmailUtils emailUtils;
private Spec11RegistrarThreatMatchesParser parser;
private ArgumentCaptor<EmailMessage> contentCaptor;
private final LocalDate date = new LocalDate(2018, 7, 15);
@@ -109,13 +110,10 @@ class Spec11EmailUtilsTest {
@BeforeEach
void beforeEach() throws Exception {
emailService = mock(SendEmailService.class);
parser = mock(Spec11RegistrarThreatMatchesParser.class);
when(parser.getRegistrarThreatMatches(date)).thenReturn(sampleThreatMatches());
contentCaptor = ArgumentCaptor.forClass(EmailMessage.class);
emailUtils =
new Spec11EmailUtils(
emailService,
gmailClient,
new InternetAddress("my-receiver@test.com"),
new InternetAddress("abuse@test.com"),
ImmutableList.of(
@@ -138,7 +136,7 @@ class Spec11EmailUtilsTest {
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
sampleThreatMatches());
// We inspect individual parameters because Message doesn't implement equals().
verify(emailService, times(3)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(3)).sendEmail(contentCaptor.capture());
List<EmailMessage> capturedContents = contentCaptor.getAllValues();
validateMessage(
capturedContents.get(0),
@@ -176,7 +174,7 @@ class Spec11EmailUtilsTest {
"Super Cool Registry Daily Threat Detector [2018-07-15]",
sampleThreatMatches());
// We inspect individual parameters because Message doesn't implement equals().
verify(emailService, times(3)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(3)).sendEmail(contentCaptor.capture());
List<EmailMessage> capturedMessages = contentCaptor.getAllValues();
validateMessage(
capturedMessages.get(0),
@@ -217,7 +215,7 @@ class Spec11EmailUtilsTest {
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
sampleThreatMatches());
// We inspect individual parameters because Message doesn't implement equals().
verify(emailService, times(2)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(2)).sendEmail(contentCaptor.capture());
List<EmailMessage> capturedContents = contentCaptor.getAllValues();
validateMessage(
capturedContents.get(0),
@@ -250,7 +248,7 @@ class Spec11EmailUtilsTest {
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
sampleThreatMatches());
// We inspect individual parameters because Message doesn't implement equals().
verify(emailService, times(3)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(3)).sendEmail(contentCaptor.capture());
List<EmailMessage> capturedContents = contentCaptor.getAllValues();
validateMessage(
capturedContents.get(0),
@@ -289,7 +287,7 @@ class Spec11EmailUtilsTest {
doThrow(new RuntimeException(new MessagingException("expected")))
.doNothing()
.doNothing()
.when(emailService)
.when(gmailClient)
.sendEmail(contentCaptor.capture());
RuntimeException thrown =
assertThrows(
@@ -305,7 +303,7 @@ class Spec11EmailUtilsTest {
.isEqualTo("Emailing Spec11 reports failed, first exception:");
assertThat(thrown).hasCauseThat().hasMessageThat().isEqualTo("expected");
// Verify we sent an e-mail alert
verify(emailService, times(3)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(3)).sendEmail(contentCaptor.capture());
List<EmailMessage> capturedMessages = contentCaptor.getAllValues();
validateMessage(
capturedMessages.get(0),
@@ -338,7 +336,7 @@ class Spec11EmailUtilsTest {
@Test
void testSuccess_sendAlertEmail() throws Exception {
emailUtils.sendAlertEmail("Spec11 Pipeline Alert: 2018-07", "Alert!");
verify(emailService).sendEmail(contentCaptor.capture());
verify(gmailClient).sendEmail(contentCaptor.capture());
validateMessage(
contentCaptor.getValue(),
"abuse@test.com",
@@ -363,7 +361,7 @@ class Spec11EmailUtilsTest {
Spec11EmailSoyInfo.MONTHLY_SPEC_11_EMAIL,
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
sampleThreatMatches());
verify(emailService, times(3)).sendEmail(contentCaptor.capture());
verify(gmailClient, times(3)).sendEmail(contentCaptor.capture());
assertThat(contentCaptor.getAllValues().get(0).recipients())
.containsExactly(new InternetAddress("johndoe@theregistrar.com"));
}
@@ -23,7 +23,7 @@ import google.registry.model.console.UserTest;
import google.registry.model.contact.ContactTest;
import google.registry.model.domain.DomainSqlTest;
import google.registry.model.domain.token.AllocationTokenTest;
import google.registry.model.domain.token.PackagePromotionTest;
import google.registry.model.domain.token.BulkPricingPackageTest;
import google.registry.model.history.ContactHistoryTest;
import google.registry.model.history.DomainHistoryTest;
import google.registry.model.history.HostHistoryTest;
@@ -82,6 +82,7 @@ import org.junit.runner.RunWith;
BeforeSuiteTest.class,
AllocationTokenTest.class,
BillingBaseTest.class,
BulkPricingPackageTest.class,
ClaimsListDaoTest.class,
ContactHistoryTest.class,
ContactTest.class,
@@ -91,7 +92,6 @@ import org.junit.runner.RunWith;
DomainHistoryTest.class,
HostHistoryTest.class,
LockTest.class,
PackagePromotionTest.class,
PollMessageTest.class,
PremiumListDaoTest.class,
RdeRevisionTest.class,
@@ -80,11 +80,12 @@ public abstract class CommandTestCase<C extends Command> {
RegistryToolEnvironment.UNITTEST.setup(systemPropertyExtension);
command = newCommandInstance();
// Capture standard output/error.
// Capture standard output/error. Use a single-byte encoding to emulate platforms where default
// charset is not UTF_8.
oldStdout = System.out;
System.setOut(new PrintStream(new OutputSplitter(System.out, stdout)));
System.setOut(new PrintStream(new OutputSplitter(System.out, stdout), false, "US-ASCII"));
oldStderr = System.err;
System.setErr(new PrintStream(new OutputSplitter(System.err, stderr)));
System.setErr(new PrintStream(new OutputSplitter(System.err, stderr), false, "US-ASCII"));
}
@AfterEach
@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@@ -32,16 +32,16 @@ import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link google.registry.tools.CreatePackagePromotionCommand}. */
public class CreatePackagePromotionCommandTest
extends CommandTestCase<CreatePackagePromotionCommand> {
/** Unit tests for {@link CreateBulkPricingPackageCommand}. */
public class CreateBulkPricingPackageCommandTest
extends CommandTestCase<CreateBulkPricingPackageCommand> {
@Test
void testSuccess() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -55,20 +55,20 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(500);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(100);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(500);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
void testFailure_tokenIsNotPackageType() throws Exception {
void testFailure_tokenIsNotBulkType() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
@@ -90,7 +90,7 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo("The allocation token must be of the PACKAGE token type");
.isEqualTo("The allocation token must be of the BULK_PRICING token type");
}
@Test
@@ -107,16 +107,16 @@ public class CreatePackagePromotionCommandTest
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo(
"An allocation token with the token String abc123 does not exist. The package token"
+ " must be created first before it can be used to create a PackagePromotion");
"An allocation token with the token String abc123 does not exist. The bulk token"
+ " must be created first before it can be used to create a BulkPricingPackage");
}
@Test
void testFailure_packagePromotionAlreadyExists() throws Exception {
void testFailure_bulkPricingPackageAlreadyExists() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -129,9 +129,9 @@ public class CreatePackagePromotionCommandTest
"--price=USD 1000.00",
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@@ -142,7 +142,8 @@ public class CreatePackagePromotionCommandTest
"--price=USD 1000.00",
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage()).isEqualTo("PackagePromotion with token abc123 already exists");
assertThat(thrown.getMessage())
.isEqualTo("BulkPricingPackage with token abc123 already exists");
}
@Test
@@ -150,7 +151,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -158,16 +159,16 @@ public class CreatePackagePromotionCommandTest
.setDiscountFraction(1)
.build());
runCommandForced("--price=USD 1000.00", "--next_billing_date=2012-03-17", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(0);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(0);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(0);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(0);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -175,7 +176,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -184,15 +185,15 @@ public class CreatePackagePromotionCommandTest
.build());
runCommandForced("--max_domains=100", "--max_creates=500", "--price=USD 1000.00", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(500);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate()).isEqualTo(END_OF_TIME);
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(100);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(500);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate()).isEqualTo(END_OF_TIME);
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -200,7 +201,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -217,6 +218,6 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo("PackagePrice is required when creating a new package");
.isEqualTo("BulkPrice is required when creating a new bulk pricing package");
}
}
@@ -379,8 +379,8 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Invalid value for -t parameter. Allowed values:[DEFAULT_PROMO, PACKAGE, SINGLE_USE,"
+ " UNLIMITED_USE]");
"Invalid value for -t parameter. Allowed values:[BULK_PRICING, DEFAULT_PROMO, PACKAGE,"
+ " SINGLE_USE, UNLIMITED_USE]");
}
@Test
@@ -399,7 +399,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
}
@Test
void testFailure_invalidPackageTokenStatusTransition() {
void testFailure_invalidBulkTokenStatusTransition() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@@ -408,14 +408,14 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
"--number",
"999",
"--type",
"PACKAGE",
"BULK_PRICING",
String.format(
"--token_status_transitions=\"%s=NOT_STARTED,%s=VALID,%s=ENDED\"",
START_OF_TIME, fakeClock.nowUtc(), fakeClock.nowUtc().plusDays(1)))))
.hasMessageThat()
.isEqualTo(
"PACKAGE tokens should not be generated with ENDED or CANCELLED in their transition"
+ " map");
"BULK_PRICING tokens should not be generated with ENDED or CANCELLED in their"
+ " transition map");
}
@Test

Some files were not shown because too many files have changed in this diff Show More